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
1
vote
1 answer

boost::named_mutex: Safely cleaning up when last process closes

I have a resource which I need to protect access to within a process, and across multiple processes. I've managed this by creating a named mutex via boost::interprocess:named_recursive_mutex, and it works great. #include…
Cloud
  • 18,753
  • 15
  • 79
  • 153
1
vote
2 answers

C++ / boost::scoped_lock : compiler warnings missing

I'm wondering if it is possible to configure the c++ compiler so that it emits a warning when someone instatiates a scoped_lock but forgets to assign it to a variable. See the examples below: Case 1.1 and case 2.1 show the intended use of the…
Pascal T.
  • 3,866
  • 4
  • 33
  • 36
1
vote
2 answers

Boost w/ C++ - Curious mutex behavior

I'm experimenting with Boost threads, as it's to my knowledge I can write a multi-threaded Boost application and compile it in Windows or Linux, while pthreads, which I'm more familiar with, is strictly for use on *NIX systems. I have the following…
Cloud
  • 18,753
  • 15
  • 79
  • 153
1
vote
1 answer

boost shared mutex check if locked in the same thread

When I write multi-thread algorithms I find for some methods useful to have expectation about the state of the mutex. For some is it already locked, for some that it is not. I come up with approach how to assert if the mutex has to be locked…
gsf
  • 6,612
  • 7
  • 35
  • 64
1
vote
1 answer

Is this a case for a mutex?

I have a thread that captures data from a device. I start/stop the thread from a gui. At the moment, the thread periodically checks a bool member isCapturingEnabled in the appcontext. I toggle this bool member from the gui to stop the thread. Is…
tzippy
  • 6,458
  • 30
  • 82
  • 151
1
vote
1 answer

Do all threads in boost::thread_group share the same thread with respect to boost::recursive_mutex

I suspect that based on the behavior of my code that if I have a boost::thread_group accessing an object protected by a boost::recursive_mutex that the mutex does not prevent threads from within the group from simultaneously entering the protected…
Jason Harrison
  • 922
  • 9
  • 27
1
vote
1 answer

Boost shared memory and synchronized queue issue/crash in consumer process

I'm trying to consume from a child process a synchronized queue in c++. I'm using this synchronized queue in C++ () (http://www.internetmosquito.com/2011/04/making-thread-safe-queue-in-c-i.html) I modified the queue to be serializable in boost and…
1
vote
1 answer

Are boost::unique_locks granted in the order that they are called?

I've examined the documentation on Boost Synchronization, and I cannot seem to determine if a boost::unique_lock will attain its lock in order. In other words, if two threads are contending to lock a mutex which is already locked, will the order…
user1382306
1
vote
1 answer

Difference between mutex.timed_lock(duration) and boost::timed_mutex::scoped_lock scoped_lock(mutex, duration)

I would like to know which is the difference between: boost::timed_mutex _mutex; if(_mutex.timed_lock(boost::get_system_time() + boost::posix_time::milliseconds(10))){ exclusive code _mutex.unlock(); } and boost::timed_mutex…
1
vote
2 answers

Process while waiting for mutex lock

Is there some way to execute a code section while waiting for a mutex to lock? The only true internal hit to my application's performance is database interaction, and there are times where I need strict synchronization which because of the database…
user1382306
1
vote
1 answer

prevent browser from closing with firebreath Plugin

I have a plugin where I want to prevent the browser from closing as im saving some data that take a unknown random amount of time. data_ready = false; data_ready = saveData(); //using a random amount of time as the user has to specify a…
1
vote
2 answers

mutex and threads independence

I run the following program on a 32 cores computer: #include #include #include using namespace std; boost::thread_group g; boost::mutex _mtx; class A{ public: void foo() { for(int ix = 0;…
cpp
  • 3,743
  • 3
  • 24
  • 38
1
vote
0 answers

WaitForMultpleObjects in boost (any updates?)

Well, I was just trying to port some code from a WIN32 application to a multiplatform application using boost. Everything was going smoothly until I hit the "WaitForMultipleObjects" problem. Basically, I have a few different boost::recursive_mutexes…
IdeaHat
  • 7,641
  • 1
  • 22
  • 53
1
vote
2 answers

Using Boost mutex in two different classes

i am using boost mutex in MessageQueue class as a private member in the following method void MessageQueue::Dequeuee() { Request rq(messageWareHouse.front().reqID,messageWareHouse.front().seq, …
Navin
  • 554
  • 2
  • 9
  • 31
1
vote
0 answers

boost::lock_guard waits forever

I'm developing a LRU-cache in C++, using boost mutexes and locks, in a multi-threaded environment. The architecture is based on a boost::unordered_map + a lock-free-queue Insertions work in non-blocking mode (try_lock), but removals should lock the…
Grana
  • 7
  • 2