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.**