Turi Create
4.0
|
#include <core/storage/sframe_data/unfair_lock.hpp>
This class implements a completely unfair lock.
The basic mechanic of operation is that every thread is assigned a priority ID (this is via a thread local variable) (rant if apple compiler has proper C++11 support this would just be using the thread_local keyword. But we don't. So it is this annoying boilerplate around pthread_getspecific.).
Then if many threads are contending for the lock, the lock will always go to the thread with the lowest priority ID.
Furthermore, the lock has a parameterized "stickiness". In other words, when a thread releases the lock, it is granted a certain time window in which if it (or a lower ID thread) returns to acquire the lock, it will be able to get it immediately. This "stickness" essentially parameterizes the CPU-utilization Disk-utilization balance. The more IO bound a task is, the better it is for it to be executed on just one CPU. This threshold attempts to self-tune by trying to maximize the total throughput of the lock. (i.e.. maximising lock acquisitions per second). This is done by gradually adapting the sleep interval: i.e. if increasing it increases throughput, it gets increases, and vice versa.
Definition at line 44 of file unfair_lock.hpp.