lets have example..
some complex work is divided by 4 thread
thread -A is calling function_A
thread -B is calling function_B
thread -C is calling function_C
thread -D is calling function_D
now condition is that thread A,B,C can work at same time but when ever thread D is executing function_D it will see does any thread from A,B,C is executing there function ? if yes then it will wait for them completion and when no thread from a,b,c is executing there function, thread D will start to execute function D.
How can i do that ? any ruff idea?
EDIT : function_A,function_B,function_c is using one handle. and function_D is closing that handle. When ever any function is using that handle it should not be closed by function_d.
This sounds like a job for a counting semaphore.
Each thread using the handle should increment the semaphore value. Thread D should wait on the semaphore to reach zero.
If you implement this without care for when thread D runs, do not be surprised if thread D runs before A, B or C and closes the handle immediately.