Multithreading, when to yield versus sleep
问题 To clarify terminology, yield is when thread gives up its time slice. My platform of interest is POSIX threads, but I think the question is general. Suppose I have consumer/producer pattern. If I want to throttle either consumer or producer, which is better to use, sleep or yield? I am mostly interested in efficiency of using either function. 回答1: The "right" way to code a producer / consumer is to have the consumer wait for the producer's data. You can achieve this by using a synchronization