C++: static function member shared between threads, can block all?
- by mhambra
Hi all,
I have a class, which has static function defined to work with C-style extern C { static void callback(foo bar) { } }. // static is defined in header.
Three objects (each in separate pthread) are instantiated from this class, each of them has own loop (in class constructor), which can receive the callback.
The pointer to function is passed as:
x = init_function(h, queue_id, &callback, NULL);
while(1) { loop_function(x); }
So each thread has the same pointer to &callback.
Callback function can block for minutes.
Each thread object, excluding the one which got the blocking callback, can call callback again.
If the callback function exists only once, then any thread attempting to callback will also block. This would give me an undesired bug, circa is interesting to ask: can anything in C++ become acting this way? Maybe, due to extern { } or some pointer usage?