lock_t
(enum
)blocked_queue
(linked list ofpcb_t
) for threads waiting on a resource
lock_init(l)
initializes lockl
– no thread initially holds itlock_acquire(l)
:- if no thread holds
l
:- mark
l
as held - return
- mark
- if another thread holds
l
:- use
scheduler.c:block()
to put the thread on theblocked_queue
- use
- if
l
has not been initialized:- return error
- if
l
has already been acquired by this thread:- return error
- if no thread holds
lock_release(l)
:- if no threads are waiting on the
blocked_queue
:- mark
l
as not being held - return
- mark
- if at least one thread is waiting on the
blocked_queue
:l
remains locked- thread at the head of the
blocked_queue
is put at the tail of theready_queue
- use
block()
andunblock()
correspondingly
- use
- if
l
has not been initialized:- return error
- if this thread does not hold
l
:- return error
- if no threads are waiting on the
block()
:- enqueue the
curent_running
thread to theblock_queue
- enqueue the
unblock()
:- dequeue the
current_running
thread from theblock_queue
- dequeue the