[cs33211] OS Student question
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Oct 31 00:10:46 EDT 2012
>
> I have two questions considering slide 11 from Lecture 11 LocksnCVs.
> The issue concerns the code used to implement condition variables
> using spinlocks.
> -------------------------------------------------------------------------------------------------------------------
> /* condition consists of:
> list - waiting threads
> listlock - lock protecting
> operation on list*/
>
> void wait(condition *c,
> lock *s){
> spinlock(c->listlock);
> /* add self to list */
> spinunlock(c->listlock);
> unlock(s);
> /* block current thread */
> lock(s);
> return;
> }
>
> void signal(condition *c){
> spinlock(c->listlock);
> /* remove a thread from
> list if list not empty */
> spinunlock(c->listlock);
> /* make removed thread
> runnable */
> }
> -------------------------------------------------------------------------------------------------------------------
>
> 1. When acquiring a spinlock, a boolean variable is given as an
> argument to use on a testnset operation. Here, c->listlock is given as
> an argument. Does c->listlock return some boolean value?
spinlock() is a function implemented as described in previous slides -
with testNset. spinlock() does not itself return anything, it just
spins until this process acquires the lock.
> 2. At the end of the wait() operation: unlock(s), /* block current
> thread */, lock(s). How is the current thread blocked?
Make it non-runnable, remove from fready queue. It will be made
runnable again by the signal() operation.
Thanks,
--
Mikhail
More information about the cs33211
mailing list