|
|
|
|
|
by bob1029
1301 days ago
|
|
The best pattern I've found for inter-thread communication involves CAS for a ring buffer slot on the producer (you can skip CAS if only 1 producer thread), with either busy wait or yield/sleep on the consumer(s). If you keep your sync primitive separated between consumer & producer, the worst bits of contention can be avoided. CAS is very fast when un-contended or lightly-contended. Busy waiting can be used for latency-sensitive applications where you need threads coordinating with latency bounds measured in microseconds. yield/sleep can be used to play more fairly with other processes and power, but then you are at mercy of the OS timeslice size. |
|