issue fixed, this code works.
removed fork() in thread.
this version is deadlock proof.