C++: static function member shared between threads, can block all?
Posted
by
mhambra
on Stack Overflow
See other posts from Stack Overflow
or by mhambra
Published on 2011-01-17T00:39:18Z
Indexed on
2011/01/17
0:53 UTC
Read the original article
Hit count: 179
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?
© Stack Overflow or respective owner