X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=doc%2Ftour.texi;h=d9dab057a06f88dab97099d32ef16f98badcf2fb;hb=9fd80c814b9b3f95c16a90a680250c3fd6e5b74e;hp=ed1f92be1bad527cdc7574371dc917a16f7b603b;hpb=36771800f7bfa985736db684d0c820c96db887ae;p=pintos-anon diff --git a/doc/tour.texi b/doc/tour.texi index ed1f92b..d9dab05 100644 --- a/doc/tour.texi +++ b/doc/tour.texi @@ -553,8 +553,10 @@ A semaphore initialized to 0 can be useful for waiting for an event that will happen exactly once. For example, suppose thread @var{A} starts another thread @var{B} and wants to wait for @var{B} to signal that some activity is complete. @var{A} can create a semaphore -initialized to 0, pass it to @var{B}, and then ``down'' the semaphore. -When @var{B} finishes its activity, it ``ups'' the semaphore. +initialized to 0, pass it to @var{B} as it starts it, and then +``down'' the semaphore. When @var{B} finishes its activity, it +``ups'' the semaphore. This works regardless of whether @var{A} +``downs'' the semaphore or @var{B} ``ups'' it first. Pintos declared its semaphore type and operations on them in @file{threads/synch.h}. @@ -665,22 +667,22 @@ struct condition not_full; /* @r{Signaled when the buffer is not full.} */ void put (char ch) @{ lock_acquire (&lock); - while (n == BUF_SIZE) /* @r{Can't add to @var{buf} as long as it's full.} */ - cond_wait (¬_full); - buf[head++ % BUF_SIZE] = ch; /* @r{Add @var{ch} to @var{buf}.} */ + while (n == BUF_SIZE) /* @r{Can't add to @var{buf} as long as it's full.} */ + cond_wait (¬_full, &lock); + buf[head++ % BUF_SIZE] = ch; /* @r{Add @var{ch} to @var{buf}.} */ n++; - cond_signal (¬_empty); /* @r{@var{buf} can't be empty anymore.} */ + cond_signal (¬_empty, &lock); /* @r{@var{buf} can't be empty anymore.} */ lock_release (&lock); @} char get (void) @{ char ch; lock_acquire (&lock); - while (n == 0) /* @r{Can't read from @var{buf} as long as it's empty.} */ - cond_wait (¬_empty); - ch = buf[tail++ % BUF_SIZE]; /* @r{Get @var{ch} from @var{buf}.} */ + while (n == 0) /* @r{Can't read from @var{buf} as long as it's empty.} */ + cond_wait (¬_empty, &lock); + ch = buf[tail++ % BUF_SIZE]; /* @r{Get @var{ch} from @var{buf}.} */ n--; - cond_signal (¬_full); /* @r{@var{buf} can't be full anymore.} */ + cond_signal (¬_full, &lock); /* @r{@var{buf} can't be full anymore.} */ lock_release (&lock); @} @end example