Questions tagged [boost-mutex]

The mutual exclusion classes of the Boost.Thread library are designed to serialize access to resources shared between C++ threads.

89 questions
0
votes
2 answers

Iterating over vector in one thread while other may potentially change reference

I have a vector allow_list that is periodically updated in a thread while another serves a function that checks if a certain string is in that allow_list via: if (std::find(allow_list->begin(), allow_list->end(), target_string) !=…
Baiqing
  • 1,223
  • 2
  • 9
  • 21
0
votes
3 answers

Using boost to turn single thread to multi thread

I'm trying to turn a code from a single thread to a multi thread(example, create 6 threads instead of 1) while making sure they all start and finish without any interference from each other. What would be a way to do this? Could I just do a for loop…
zxtron
  • 1
  • 2
0
votes
0 answers

lock_guard causing the line of code to be hung

I have the following code where I am using lock_guard for a named mutex so that the mutex lock gets released when the execution of code is finished (including exceptions thrown) #include using namespace…
whoami
  • 1,689
  • 3
  • 22
  • 45
0
votes
1 answer

mutex lock synchronization between different threads

Since I have recently started coding multi threaded programs this might be a stupid question. I found out about the awesome mutex and condition variable usage. From as far as I can understand there use is: Protect sections of code/shared resources…
rnv
  • 27
  • 9
0
votes
1 answer

Boost named mutexes in docker containers

In our project we are using some network library with tricky rules to obey. One of them is that we should manually create some int identity that should be unique per process on same host (it should also be in specific range so we cannot use…
ice
  • 44
  • 3
0
votes
0 answers

Having multiple reader locks in a single thread

I have data coupled with a Lock = boost::shared_mutex. I am locking data access with reader locks ReadLock = boost::shared_lock and writer locks WriteLock = boost::unique_lock. Obviously, lots of readers may be reading the data at a…
Bill Kotsias
  • 3,258
  • 6
  • 33
  • 60
0
votes
0 answers

Mutex inside templated struct causes segmentation fault

For exchanging data between classes, I use a kind of "main-hub-class", from which each other class can access the data. Now, to make this thread-safe I came up with a templated struct that holds a variable and a boost::shared_mutex for that…
0
votes
1 answer

Undefined reference for boost::mutex in struct

I want to use a boost::mutex for the function add of my struct Cell. Here is the definition of my struct in Detector.h class Detector { private: struct Cell{ static boost::mutex mutex_; double energy; double…
Marie
  • 1
  • 2
0
votes
1 answer

The execution sequence after conditional variable notify

There are two threads (Call them T1 and T2) that sync with each other by boost condition variable and mutex like: boost::condition_variable global_cond; boost::mutex global_mutex; boost::unique_lock lock( global_mutex); thread1() { …
user2191818
  • 39
  • 1
  • 4
0
votes
1 answer

OpenMP v.2.0 or Boost thread 1.59

I am wondering how I can parallelise for loop below in a secure way. I found some possible solution like this . However I am limited to use OpenMP version 2.0 and Boost version 1.59. algorithm explanation: It iterates over all of my triangles which…
H'H
  • 1,638
  • 1
  • 15
  • 39
0
votes
0 answers

How do I asure thread safety when accessing class members with multiple threads

I am trying to get thread synchronization to work. Below is a sample code (Runnable C++ shell example) for illustration. When I run the program, the three member functions bar1(), bar2() and bar3() are executed. My aim though is to use one thread…
tzippy
  • 6,458
  • 30
  • 82
  • 151
0
votes
1 answer

Pass class object having mutex to boost::thread by reference

I would like to start multiple instances of a function which performs some calculations. The function takes a class object and as the class includes a shared_mutex I pass it by reference so all threads access the class via the same object. If I try…
droid192
  • 2,011
  • 26
  • 43
0
votes
0 answers

Use boost::interprocess::mutex to synchronize shared memory access

I am having two different applications developed in C++. These applications communicate each other via boost::interprocess::shared_memory_object. Now I require a mutex variable to sync the operations between the two.. Can somebody provide a minimal…
Jackzz
  • 1,417
  • 4
  • 24
  • 53
0
votes
1 answer

Boost Thread start failure if thread object declared as member

i've written a class named Task which encapsulates a boost::thread and allow to override the run() method to do some job on the newly created thread. Here is the base class: class Task { typedef boost::function TaskEventCallback; …
Gianks
  • 63
  • 1
  • 15
0
votes
2 answers

Boost interprocess mutex crashes instead of waiting on a lock?

I've been at this for quite a few days (even posted on the boost forum) and being able to make a second process recognize a locked mutex just doesn't seem to work. Please help. This is the code: A common header file: SharedObject.hpp #ifndef…
Nav
  • 19,885
  • 27
  • 92
  • 135