There are:
one conditional variable "var": values of var can be 0 or 1 only;
one provider thread "thP": when received data from net, set var 1 (available);
one consumer thread "thC": wait() for var. When got var, set it 0 (unavailable), and process something afterwards.
.
I found two ways to implement this simple model:
(1) Use pthread_cond_t as var. This method needs an additional mutex and a callback function to unlock mutex while thread will be cleaned.
(2) Use sem_t as var. This method may cause a situation as "var>1". thC may do more than one wait() operations to decrease the var's value to 1.
.
Question is:
To implement this simple model "single provider, single consumer, one conditional variable", which type should I use for var, pthread_cond_t, sem_t or simply using pthread_mutex_t as a binary semaphore?
.
Thanks very much!