I have developed a c program that uses pthreads. one of the threads reads a file 5 bytes at a time and puts the data to a ring buffer ( array of structures of length 3) the buffer is assumed to wrap around after the index 2 to 0. Another thread reads the ring buffer and puts it to an output file.
Threads are synchronised using mutexs and condition variables. The programs runs fine sometimes but gets stuck into deadlocks often ( deadlock 40% of the time). Please help me sort out the deadlock issue. Iam not able to trace the reason of deadlock . I will post the code in my next comment.