does c++ lock work for self-modifying code

39 Views Asked by At

I want to modify my function in multi threads env. like can c++ lock clear instruction cache like __builtin___clear_cache in gcc

// thread 1
boost::unique_lock<boost::shared_mutex> lock(func_mutext);
mprotect(page_start, page_len, PROT_WRITE | PROT_EXEC);
void* func_addr = &func_abc;
memcpy(func_addr , instruction, ins_len); // modify func_abc code here
mprotect(page_start, page_len, PROT_EXEC);

// thread 2 3 4
while(true)
{
    boost::shared_lock<boost::shared_mutex> lock(func_mutext);
   func_abc(123); // does it work?
}
0

There are 0 best solutions below