tag:blogger.com,1999:blog-7412059039196297644.post3661635548142308119..comments2023-05-03T00:30:03.873-07:00Comments on Coding ways: Producer Consumer Pattern implementation using pthreadAnonymoushttp://www.blogger.com/profile/01943168256481763086noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7412059039196297644.post-1083554267504359142013-07-14T23:11:43.324-07:002013-07-14T23:11:43.324-07:00Hi OetelaarNG,
Appreciating your comment:
1. pthre...Hi OetelaarNG,<br />Appreciating your comment:<br />1. pthread_cond_wait(...) unlocks "mLock" and let's other thread work on data store.<br />2. <br />---- Add(..) ---<br /> pthread_mutex_unlock(&mLock);<br /> pthread_cond_signal(&mFullCond);<br />---<br />we need to unlock here because if we don't, consumer can't peekup data from store!<br />3. By the way this is a sample for single producer/single consumer.<br />for multiple producer/multiple consumer, some conditions and extra works are needed.<br />----<br />Thanks for your comment.<br />Anonymoushttps://www.blogger.com/profile/01943168256481763086noreply@blogger.comtag:blogger.com,1999:blog-7412059039196297644.post-48368566711726488772013-05-16T06:51:14.119-07:002013-05-16T06:51:14.119-07:00I think this code has some serious issues.
As I se...I think this code has some serious issues.<br />As I see it your condition_wait() are not checking the predicate in a loop.<br />Furthermore you unlock() before you call cond_signal() which is also inviting races.<br />I hope people do not copy this code as an example.#oetelxhttps://www.blogger.com/profile/12267942602097098851noreply@blogger.com