+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker thread (not including the controller)
+ * when it has no more work to do.
+ *
+ * \param parmap a parmap
+ * \param round the expected round number
+ */
+static void xbt_parmap_posix_worker_wait(xbt_parmap_t parmap, unsigned round)
+{
+ xbt_os_mutex_acquire(parmap->ready_mutex);
+ /* wait for more work */
+ if (parmap->work != round) {
+ xbt_os_cond_wait(parmap->ready_cond, parmap->ready_mutex);
+ }
+ xbt_os_mutex_release(parmap->ready_mutex);
+}
+
+#ifdef HAVE_FUTEX_H
+/**
+ * \brief Starts the parmap: waits for all workers to be ready and returns.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_futex_master_wait(xbt_parmap_t parmap)
+{
+ unsigned count = parmap->thread_counter;
+ while (count < parmap->num_workers) {
+ /* wait for all workers to be ready */
+ futex_wait(&parmap->thread_counter, count);
+ count = parmap->thread_counter;
+ }
+}
+
+/**
+ * \brief Ends the parmap: wakes the controller thread when all workers terminate.
+ *
+ * This function is called by all worker threads when they end (not including
+ * the controller).
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_futex_worker_signal(xbt_parmap_t parmap)
+{
+ unsigned count = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (count == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ futex_wake(&parmap->thread_counter, INT_MAX);
+ }
+}
+
+/**
+ * \brief Wakes all workers and waits for them to finish the tasks.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_futex_master_signal(xbt_parmap_t parmap)
+{
+ parmap->thread_counter = 1;
+ __sync_add_and_fetch(&parmap->work, 1);
+ /* wake all workers */
+ futex_wake(&parmap->work, INT_MAX);
+}
+
+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker thread (not including the controller)
+ * when it has no more work to do.
+ *
+ * \param parmap a parmap
+ * \param round the expected round number
+ */
+static void xbt_parmap_futex_worker_wait(xbt_parmap_t parmap, unsigned round)
+{
+ unsigned work = parmap->work;
+ /* wait for more work */
+ while (work != round) {
+ futex_wait(&parmap->work, work);
+ work = parmap->work;
+ }
+}
+#endif
+
+/**
+ * \brief Starts the parmap: waits for all workers to be ready and returns.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_busy_master_wait(xbt_parmap_t parmap)
+{
+ while (parmap->thread_counter < parmap->num_workers) {
+ xbt_os_thread_yield();
+ }
+}
+
+/**
+ * \brief Ends the parmap: wakes the controller thread when all workers terminate.
+ *
+ * This function is called by all worker threads when they end.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_busy_worker_signal(xbt_parmap_t parmap)
+{
+ __sync_add_and_fetch(&parmap->thread_counter, 1);
+}
+
+/**
+ * \brief Wakes all workers and waits for them to finish the tasks.
+ *
+ * This function is called by the controller thread.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_busy_master_signal(xbt_parmap_t parmap)
+{
+ parmap->thread_counter = 1;
+ __sync_add_and_fetch(&parmap->work, 1);
+}
+
+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker thread (not including the controller)
+ * when it has no more work to do.
+ *
+ * \param parmap a parmap
+ * \param round the expected round number
+ */
+static void xbt_parmap_busy_worker_wait(xbt_parmap_t parmap, unsigned round)
+{
+ /* wait for more work */
+ while (parmap->work != round) {
+ xbt_os_thread_yield();