aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2016-05-05 16:53:15 -0700
committerLuis R. Rodriguez <mcgrof@kernel.org>2016-05-06 16:01:54 -0700
commitee6dadfbec14f21c30a8188bc1afa40d0ba35510 (patch)
tree6d23c86f3726ba5744bd7492050e7e0eb726d0d6
parent99381126182f95b53f2ddce0943da447c09088e8 (diff)
downloadcocci-tact-ee6dadfbec14f21c30a8188bc1afa40d0ba35510.tar.gz
try to fix eating
If we place the lock when eating we try to ensure everyone takes food, but the state machine is all messed up still. The trash is still not being dealt with at all. This is still broken, we need a way to ensure so that the mutex is held also for the trash, likewise for the accounting which provides the simple state machine. Run 1: Before party: FOOD: [ ******************************* ] TRASH: [ ] After party: FOOD: [ ****************************** ] TRASH: [ ******************************* ] Run 2: Before party: FOOD: [ ******************************* ] TRASH: [ ] After party: FOOD: [ * ***************************** ] TRASH: [ ******************************* ] Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
-rw-r--r--main.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/main.c b/main.c
index f977ce8..5f589cc 100644
--- a/main.c
+++ b/main.c
@@ -42,6 +42,7 @@ void eat(long tid)
bool eat_in_order = true;
long t;
+ pthread_mutex_lock(&party->mutex);
/* If anyone ate out of place lets take notice of that... */
for (t=0; t < NUM_THREADS; t++) {
if (t == tid)
@@ -56,6 +57,7 @@ void eat(long tid)
if (party->food[tid])
if (eat_in_order)
party->food[tid] = 0;
+ pthread_mutex_unlock(&party->mutex);
}
void cleanup(long tid)