diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2017-09-02 14:52:35 +1000 |
---|---|---|
committer | Chris Sherlock <chris.sherlock79@gmail.com> | 2017-09-02 15:06:07 +1000 |
commit | 7e5da42c3d860eff7ca25c579f721f8567de2f78 (patch) | |
tree | bd13adbf188f2b63591842df56df9a0ec74c014d | |
parent | 1103e3c341a3a200f7415795097ba1d6df89def0 (diff) |
sal workbench: fix monitor.cxx - need to release and acquire mutex
private/tbsdy/workbench
Change-Id: I0bf23241f2fd510914e758a1ff491845c33bc401
-rw-r--r-- | sal/workben/osl/thread/monitor.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sal/workben/osl/thread/monitor.cxx b/sal/workben/osl/thread/monitor.cxx index 99e0d80f5d44..0e5cbefa7c90 100644 --- a/sal/workben/osl/thread/monitor.cxx +++ b/sal/workben/osl/thread/monitor.cxx @@ -69,7 +69,22 @@ void produce(void* /* pData */) osl_acquireMutex(queueMutex); while (nItemCount == BUFFER_SIZE-1) + { + /* we aren't doing anything to the queue, so release + the mutex and then reacquire it after waiting. + Without this, we eventually hit a "missed wakeup" + condition, whereby the thread is sleeping due to + waiting on the condition variable, but another + thread preemptively switched right before the + thread went to sleep and another thread sets the + condition variable... but of course then it switches + back to this thread which then waits forever as it + has missed its wakeup event... + */ + osl_releaseMutex(queueMutex); osl_waitCondition(fullOrEmpty, nullptr); + osl_acquireMutex(queueMutex); + } fprintf(stdout, "produce()\n"); @@ -98,7 +113,15 @@ void consume(void* /* pData */) osl_acquireMutex(queueMutex); while (nItemCount == 0) + { + /* We aren't doing anything to the queue, so release + the mutex and then reacquire it after waiting. See + comments in produce() for the reasoning. + */ + osl_releaseMutex(queueMutex); osl_waitCondition(fullOrEmpty, nullptr); + osl_acquireMutex(queueMutex); + } fprintf(stdout, "consume()\n"); |