I have a function (my_func) which can be called by a program that has multiple thread. And I don’t want this function to be executed twice or more in the same time. Because I’m writing in memory, and I don’t want them to write in the same time.
void my_func()
{
// I want a line that blocks the execution if one is still pending
/* the code here */
}
use mutex lock at the beginning of your function and mutex unlock before going out from your function
You can do it in other way if you want:
and in your code you call
MY_FUNC_MACRO()instead ofmy_func()