#if HAVE_THREAD_CONTEXTS
simgrid::xbt::Parmap<smx_actor_t>* ParallelBoostContext::parmap_;
-uintptr_t ParallelBoostContext::threads_working_;
+std::atomic<uintptr_t> ParallelBoostContext::threads_working_;
xbt_os_thread_key_t ParallelBoostContext::worker_id_key_;
std::vector<ParallelBoostContext*> ParallelBoostContext::workers_context_;
void ParallelBoostContext::resume()
{
- uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
+ uintptr_t worker_id = threads_working_.fetch_add(1, std::memory_order_relaxed);
xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast<void*>(worker_id));
ParallelBoostContext* worker_context = static_cast<ParallelBoostContext*>(SIMIX_context_self());
#include <boost/context/detail/fcontext.hpp>
#endif
+#include <atomic>
#include <cstdint>
#include <functional>
#include <vector>
private:
static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
static std::vector<ParallelBoostContext*> workers_context_;
- static uintptr_t threads_working_;
+ static std::atomic<uintptr_t> threads_working_;
static xbt_os_thread_key_t worker_id_key_;
};
#endif
#if HAVE_THREAD_CONTEXTS
simgrid::xbt::Parmap<smx_actor_t>* ParallelRawContext::parmap_;
-uintptr_t ParallelRawContext::threads_working_; /* number of threads that have started their work */
+std::atomic<uintptr_t> ParallelRawContext::threads_working_; /* number of threads that have started their work */
xbt_os_thread_key_t ParallelRawContext::worker_id_key_; /* thread-specific storage for the thread id */
std::vector<ParallelRawContext*> ParallelRawContext::workers_context_; /* space to save the worker context
in each thread */
XBT_DEBUG("No more processes to run");
uintptr_t worker_id = reinterpret_cast<uintptr_t>(xbt_os_thread_get_specific(worker_id_key_));
next_context = workers_context_[worker_id];
- XBT_DEBUG("Restoring worker stack %zu (working threads = %zu)", worker_id, threads_working_);
+ XBT_DEBUG("Restoring worker stack %zu (working threads = %zu)", worker_id, threads_working_.load());
}
SIMIX_context_set_current(next_context);
void ParallelRawContext::resume()
{
- uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
+ uintptr_t worker_id = threads_working_.fetch_add(1, std::memory_order_relaxed);
xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast<void*>(worker_id));
ParallelRawContext* worker_context = static_cast<ParallelRawContext*>(SIMIX_context_self());
workers_context_[worker_id] = worker_context;
#ifndef SIMGRID_SIMIX_RAW_CONTEXT_HPP
#define SIMGRID_SIMIX_RAW_CONTEXT_HPP
+#include <atomic>
#include <cstdint>
#include <functional>
#include <vector>
private:
static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
static std::vector<ParallelRawContext*> workers_context_;
- static uintptr_t threads_working_;
+ static std::atomic<uintptr_t> threads_working_;
static xbt_os_thread_key_t worker_id_key_;
};
#endif
#if HAVE_THREAD_CONTEXTS
simgrid::xbt::Parmap<smx_actor_t>* ParallelUContext::parmap_;
-uintptr_t ParallelUContext::threads_working_; /* number of threads that have started their work */
+std::atomic<uintptr_t> ParallelUContext::threads_working_; /* number of threads that have started their work */
xbt_os_thread_key_t ParallelUContext::worker_id_key_; /* thread-specific storage for the thread id */
std::vector<ParallelUContext*> ParallelUContext::workers_context_; /* space to save the worker's context
* in each thread */
void ParallelUContext::resume()
{
// What is my containing body?
- uintptr_t worker_id = __sync_fetch_and_add(&threads_working_, 1);
+ uintptr_t worker_id = threads_working_.fetch_add(1, std::memory_order_relaxed);
// Store the number of my containing body in os-thread-specific area :
xbt_os_thread_set_specific(worker_id_key_, reinterpret_cast<void*>(worker_id));
// Get my current soul:
#include <ucontext.h> /* context relative declarations */
+#include <atomic>
#include <cstdint>
#include <functional>
#include <vector>
private:
static simgrid::xbt::Parmap<smx_actor_t>* parmap_;
static std::vector<ParallelUContext*> workers_context_;
- static uintptr_t threads_working_;
+ static std::atomic<uintptr_t> threads_working_;
static xbt_os_thread_key_t worker_id_key_;
};
#endif