Race condition and warning fixed. Added infinite loop.
Need to change condition variables to semaphores.