문제

Is there any standard threading library for Linux which implements hybrid mutex capabilities? I mean, a mutex which, at first, "behaves like a spinlock" and "only if the lock has still not been obtained after a certain amount of time (or retries or any other measuring factor), the thread is really put to sleep", as mentioned by Mecky at When should one use a spinlock instead of mutex?

도움이 되었습니까?

해결책

The glibc already provides this. Just use the PTHREAD_MUTEX_ADAPTIVE_NP type or use PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP as the mutex initializer.

See http://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_mutex_lock.c#l90

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top