c++ - Passing non-thread-safe objects through thread-safe containers -
i have thread-safe object queue designed model pipeline of work moving between chain of threads. in cases, want pass non-thread-safe objects (e.g., std::vector
s, or other stl containers) part of these work items.
now, in case have shared object between threads, there obvious problem of load/store ordering in ensuring object consistency. since thread-safe queue ensures 1 thread has ownership of object there no chance multiple threads trying modify or read object @ same time.. possible problem see ensuring memory consistency in issued loads/stores on object previous owner threads.
the queue ensures thread safety creating lock_guard<...>
on queue operations. wouldn't memory consistency of object being moved between threads guaranteed since memory fencing , synchronization taken care lock_guard
?
part of me wants ensure passing thread-safe objects between threads, feel case there should no problem. true?
the queue ensures thread safety creating lock_guard<...> on queue operations. wouldn't memory consistency of object being moved between threads guaranteed since memory fencing , synchronization taken care lock_guard?
yes.
part of me wants ensure passing thread-safe objects between threads, feel case there should no problem. true?
yes.
this why volatile
inapplicable device concurrent data access in c++; doesn't solve race conditions and, once you've brought concurrency devices (e.g. mutexes) fray fix that, taking care of memory consistency issue there's nothing left volatile
do.
Comments
Post a Comment