+}
+
+/**
+ * \brief Waits for some work to process.
+ *
+ * This function is called by each worker when it has no more work to do.
+ *
+ * \param parmap a parmap
+ */
+static void xbt_parmap_wait(xbt_parmap_t parmap)
+{
+#ifdef HAVE_FUTEX_H
+ int myflag;
+ unsigned int mycount;
+
+ myflag = parmap->work;
+ mycount = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (mycount == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ parmap->done++;
+ futex_wake(&parmap->done, 1);
+ }
+
+ /* wait for more work */
+ futex_wait(&parmap->work, myflag);
+#endif
+}
+
+/**
+ * \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_end(xbt_parmap_t parmap)
+{
+#ifdef HAVE_FUTEX_H
+ unsigned int mycount;
+
+ mycount = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (mycount == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ parmap->done++;
+ futex_wake(&parmap->done, 1);
+ }
+#endif
+}