/* Microsoft wants to improve the code quality blah blah blah */
/* See: https://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx */
/* warning C4996: '_strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. */
- # define _CRT_NONSTDC_NO_WARNINGS
+ #define _CRT_NONSTDC_NO_WARNINGS
/* warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. */
- # define _CRT_SECURE_NO_WARNINGS
+ #define _CRT_SECURE_NO_WARNINGS
#endif
/* 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. */
+#include <atomic>
+
#include "internal_config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
xbt_os_thread_t *workers; /**< worker thread handlers */
void_f_pvoid_t fun; /**< function to run in parallel on each element of data */
xbt_dynar_t data; /**< parameters to pass to fun in parallel */
- unsigned int index; /**< index of the next element of data to pick */
+ std::atomic<unsigned int> index; /**< index of the next element of data to pick */
#ifdef HAVE_MC
int finish;
*/
void* xbt_parmap_next(xbt_parmap_t parmap)
{
- unsigned int index = __sync_fetch_and_add(&parmap->index, 1);
+ unsigned int index = parmap->index++;
if (index < xbt_dynar_length(parmap->data)) {
return xbt_dynar_get_as(parmap->data, index, void*);
}
static void xbt_parmap_work(xbt_parmap_t parmap)
{
unsigned index;
- while ((index = __sync_fetch_and_add(&parmap->index, 1))
+ while ((index = parmap->index++)
< xbt_dynar_length(parmap->data))
parmap->fun(xbt_dynar_get_as(parmap->data, index, void*));
}