First, to clarify, recently made several posts, some marked wait Results posted, though have yet to find a better satisfactory answer, but can also be attached to the end, and today attempts Results posted, several times failed because CSDN out a bug, not knot, hope you forgive me, bug does not end immediately after the paste.
I intend to use a listener thread select the link, another thread to receive data, when a socket has data that can be received when pthread_cond_signal immediately notify the receiving thread receives.
I received about 15 frames per second h264 data, each frame of data size is 80K or so, the thread is certainly enough time to close, so frequent thread switching operation will affect the performance of it?
discovered some time after closing pthread_cond_signal not evoke threads pthread_cond_wait up (this time the thread has been harvested data idle), how could this happen?
multi-threaded to receive data from the client service program, generally designed to compare how good?
Thank you very much!
------ Solution ------------------------------- -------------
seemingly depends on your code implements.
pthread_cond_wait () is used to block the current thread to wait for another thread to use pthread_cond_signal () or pthread_cond_broadcast to wake it up. pthread_cond_wait () must pthread_mutex necessary use. pthread_cond_wait () function into a wait state will automatically release mutex. When the other threads through pthread_cond_signal () or pthread_cond_broadcast, to wake up the thread, so that pthread_cond_wait () through (return), the thread and automatically get the mutex.
pthread_cond_signal function is to send a signal to another state is a thread is blocked waiting to release it from the blocked state and continue execution. If no threads blocked in a wait state, pthread_cond_signal also successful return .
pthread_cond_signal generally do not use the "thundering herd phenomenon", he only gave up one thread to signal. If there are multiple threads are blocked waiting for the condition variable, then it is based on the waiting thread priority level to determine which thread receives the signal starts to proceed. If the thread priorities are the same, according to the length of time to wait to determine which thread gets the signal. But in any case a pthread_cond_signal call up letter once.
But pthread_cond_signal simultaneously on multiple processors may wake up multiple threads, when you only make one thread to handle a task, the other thread to be awakened needed to continue to wait, and regulatory requirements pthread_cond_signal least pthread_cond_wait wake a thread on, in fact, some implementations for simplicity on a single processor will wake up in multiple threads.
------ Solution ------------ --------------------------------
conditions are met not sleep, did not lose it such a said.
------ Solution -------------------------------------- ------
pthread_cond_wait () must pthread_mutex supporting the use of another, wait for the best conditions to use a while loop.
------ For reference only -------------------------------------- -
which I also understand,
------ For reference only ---------------------------- -----------
found the reason: If a thread that has been pthread_cond_signal higher CPU, idle, the thread will not process received a message?
------ For reference only -------------------------------------- -
thundering herd effect is not dealt with, have been resolved.
------ For reference only -------------------------------------- -
learning of pthread_cond_wait () passing through, looking for thundering herd
没有评论:
发表评论