-/* $Id$ */
-
/* xbt_synchro -- Synchronization virtualized depending on whether we are */
/* in simulation or real life (act on simulated processes) */
/* This is the simulation implementation, using simix. */
-/* Copyright 2006,2007 Malek Cherier, Martin Quinson
- * All right reserved. */
+/* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
void *userparam;
void *father_data;
/* stuff to allow other people to wait on me with xbt_thread_join */
- int joinable;
+ int joinable:1,done:1;
xbt_cond_t cond;
xbt_mutex_t mutex;
} s_xbt_thread_t;
SIMIX_process_set_data(SIMIX_process_self(), t->father_data);
(*t->code) (t->userparam);
if (t->joinable) {
+ t->done=1;
xbt_mutex_acquire(t->mutex);
xbt_cond_broadcast(t->cond);
xbt_mutex_release(t->mutex);
()), 0, NULL,
/*props */ NULL);
res->joinable = joinable;
+ res->done = 0;
res->cond = xbt_cond_init();
res->mutex = xbt_mutex_init();
// free(name);
{
xbt_mutex_acquire(thread->mutex);
xbt_assert1(thread->joinable,"Cannot join on %p: wasn't created joinable",thread);
- xbt_cond_wait(thread->cond,thread->mutex);
- xbt_mutex_release(thread->mutex);
+ if (!thread->done) {
+ xbt_cond_wait(thread->cond,thread->mutex);
+ xbt_mutex_release(thread->mutex);
+ }
xbt_mutex_destroy(thread->mutex);
xbt_cond_destroy(thread->cond);