Implementing mutex wait in user threads

164 views Asked by At

How does the wait for a lock is implemented in user threads?

Say thread A is trying a acquire a lock that is used by another thread B. After A realized the lock is locked by other thread, what exactly does he do? How does it stops it's own execution? who runs after he stop?

I read that in kernel threads , the thread can call a syscall that suspends it and put it in a waiting queue. But in user threads the system is not aware of the threads, so is there should be a queue managed by the user?

1

There are 1 answers

0
xxa On

User threads check the availability of the lock via a system call, so the decision is made at system level, and the code that is executing has the necessary privileges to put the thread onto a waiting queue if necessary.