Man pthread_mutex_init or man pthread_mutex_lock no result solution, pthreadmutexinit
Problem:
In the newly installed Mint/Ubuntu, man pthread_mutex-related functions may not be returned,
No manual entry for pthread_mutex_init error is reported, as shown in figure
Solution:
Install manpages: manpages-posix-dev
Mint/Ubuntu: sudo apt-get install manpages-posix-dev
Result:
Try again with man.
Pthread_mutex_lock: Why is the following program not deadlocked ???
The loop wait is actually like this: if the check conditions are not met, unlock them if they are not met. Then, wait until the check is completed, lock them again, and then check. If the check conditions are not met, unlock them.
That is to say, after entering the pthread_cond_wait function, it releases the lock and waits on has_product. When has_product is triggered, it locks the lock and then outputs the function. After your consumer thread calls pthread_cond_wait, it releases the lock and does not return this function (this function will not run without returning your code). When has_product is triggered, this function gets the lock and returns it.
Let's explain that before you call this function, your thread gets the lock. When you get this function, your thread still gets the lock; but when this function is not available, your thread will release the lock.
Who can explain the features of pthread_mutex_t?
This is a thread. pthread_mutex_t is a defined variable. If a thread locks it, other threads cannot lock it, only when the first thread unlocks other threads can it continue... I don't know where your program came from.