threading question



I have a user space app that has several "threadCode" threads.
In the Main thread, FnA must execute exclusive of a part of the loop in the
thread code. For each of the threads, they must never block one another,
only FnA entry should cause the block of the threads, and then it should wait
in FnA until all the threads are at a point outside that small code block in
the threadCode.
If i could test a mutex without locking it I can do this, but i think any test
of a mutex locks the mutex if its successful. Another thought i had was to
use 2 flags. 1 flag says "Im in FnA", the other says "wait, the threadCode
section is busy". The thing with the 2 flags is though, it sounds like a
deadlock waiting to happen.

Main thread
*
1:
*
"call FnA", its ok if the thread code below
causes FnA to stall for a few seconds.
FnA must execute exclusive of a section
of the code in the threadCode loop
*
*
* Loop 1:

threadCode(multiple identical copies running)
*
*
2:
*
*
if Main thread is in FnA spin here
+=
+= If any thread is in this block, FnA must wait
+= until they all have exited this block
+= A threadCode thread must never block another
+= threadCode thread
*
*
*
*loop 2:


.



Relevant Pages

  • Re: threading question
    ... FnA must execute exclusive of a part of the loop in ... the thread code. ... If i could test a mutex without locking it I can do this, ... flags is though, it sounds like a deadlock waiting to happen. ...
    (comp.os.linux.development.apps)
  • Re: threading question
    ... FnA must execute exclusive of a part of the loop in the ... its ok if the thread code below ... this what reader/writer locks are for. ...
    (comp.os.linux.development.apps)
  • Re: threading question
    ... FnA must execute exclusive of a part of the loop in the ... Use Mutex for mutual exclusion! ...   causes FnA to stall for a few seconds. ...
    (comp.os.linux.development.apps)