How can I measure the delay of a mutex, semaphore or futex? I mean the delay between two events: unlock a previously locked mutex and lock this mutex. There are two cases: when all threads / processes are on the same processor (how long will it take to redistribute the thread), and when the first thread is on the first CPU, and the second on the second.
Thread1: Lock(Mutex) Critical1 Unlock(Mutex)|<
Or even
Thread1: work..work..very hard..work... sem_post()|<----->| Thread2: sem_wait(semaphore)...............................|sem_wait unlocks here work2..
This time is very short (~ 1 k cycles), so I cannot use gettimeofday()
source share