+static void xbt_parmap_posix_start(xbt_parmap_t parmap)
+{
+ unsigned int counter = __sync_fetch_and_add(&parmap->thread_counter, 1);
+ if (counter < parmap->num_workers) {
+ /* wait for all workers to be initialized */
+ xbt_os_cond_wait(parmap->done_cond, parmap->done_mutex);
+ }
+}
+
+/**
+ * \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_posix_end(xbt_parmap_t parmap)
+{
+ unsigned int counter = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ XBT_DEBUG("Shutting down worker %d", counter);
+ if (counter == parmap->num_workers) {
+ /* all workers have finished, wake the controller */
+ xbt_os_cond_signal(parmap->done_cond);
+ }
+}
+
+/**
+ * \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_posix_signal(xbt_parmap_t parmap)
+{
+ parmap->thread_counter = 0;
+ parmap->work++;
+ XBT_DEBUG("Starting work %d", parmap->work);
+
+ /* wake all workers */
+ xbt_os_cond_broadcast(parmap->ready_cond);
+
+ if (parmap->status == XBT_PARMAP_WORK) {
+ /* also work myself */
+ void* work = xbt_parmap_next(parmap);
+ while (work != NULL) {
+ parmap->fun(work);
+ work = xbt_parmap_next(parmap);
+ }
+ }
+
+ unsigned int counter = __sync_add_and_fetch(&parmap->thread_counter, 1);
+ if (counter < parmap->num_workers) {
+ /* some workers have not finished yet */
+ XBT_DEBUG("Some workers have not finished yet, waiting for them");
+ xbt_os_cond_wait(parmap->done_cond, parmap->done_mutex);
+ }
+}
+
+/**
+ * \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
+ */
+static void xbt_parmap_posix_wait(xbt_parmap_t parmap)