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: 154

Filed under:
|
|

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.

  1. Callback function can block for minutes.
  2. Each thread object, excluding the one which got the blocking callback, can call callback again.
  3. 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

Related posts about c++

Related posts about pthreads