Relative Content

Tag Archive for cmultithreadingsynchronizationthread-safetycircular-buffer

How to synchronize this producer consumer problem?

I’m currently working on a homework assignment for my university. We are supposed to make a circular buffer threadsafe, given a struct rbuf with two mutexes and two signals. The two mutexes can possibly be traced back to the fact that two writer and two reader threads are always active. The read and write functions work very well so far, as all tests without testing the thread safety beforehand were successful. They are basically only responsible for writing to the buffer and reading from the buffer. Also we should use pthread_cond_timedwait. My current implementation always has data races (I know this thanks to the ThreadSanitizer) and unfortunately I have absolutely no idea how to synchronize this better.