From: Ben Pfaff Date: Thu, 6 Jan 2005 04:56:25 +0000 (+0000) Subject: Fix condition variable example. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fd80c814b9b3f95c16a90a680250c3fd6e5b74e;p=pintos-anon Fix condition variable example. Thanks to Adam L Beberg for reporting this bug. --- diff --git a/doc/tour.texi b/doc/tour.texi index 845a1c8..d9dab05 100644 --- a/doc/tour.texi +++ b/doc/tour.texi @@ -667,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