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
3
votes
1 answer

Boost::Mutex in class not thread-safe

I'm learning concurrent programming and what I want to do is have a class where each object it responsible for running its own Boost:Thread. I'm a little over my head with this code because it uses A LOT of functionality that I'm not that…
Sebastian Zander
  • 347
  • 1
  • 4
  • 13
2
votes
2 answers

vector copying and multi-threading : how to ensure multi-read even if occasional writes may happen?

Pseudocode: Function1_vector_copy () { vectora = vectorb; } Function2_vector_search() { find k in vectora; } The program is multi-threaded. While many threads may search , vector copying is done only by a single thread but at occasional times. The…
King
  • 1,170
  • 2
  • 16
  • 33
2
votes
1 answer

Why is identifier "MutexType" is undefined?

Attempting to use the boost library to create a system wide mutex from the docs #include #include #include using…
loaded_dypper
  • 262
  • 3
  • 12
2
votes
2 answers

Why do I need to initialize pthread mutex in C?

I am trying to understand why pthread_mutex_init needs to be called after pthread_mutex_lock. I wrote a small program that shows that the behavior is weird when pthread_mutex_lock is called before pthread_mutex_init (see below) but I do not…
sirKobz
  • 23
  • 3
2
votes
4 answers

Std mutex or boost mutex? Which is preferable?

What is the real difference between std::mutex and boost::mutex? Which one is faster in terms of implementation and compilation? Are both of them portable?I read my questions related to it but there is no clear mention of difference . std mutex is…
seilena
  • 21
  • 1
  • 7
2
votes
3 answers

Mutex on part of class

Is it possible to use mutexes on parts of a class ? Like : class A{ int a; int b; boost::mutex Mutex_for_a; boost::mutex Mutex_for_b; } and then use the right mutex to perform the right operation. I know this is technically possible…
2
votes
1 answer

boost::mutex Release VS Debug Build

I am bulding a PCL based application, for which use the default PCL grabber code for velodyne which can seen here. When i build my application in Debug mode it's working as per the expectations, but in Release build, clouds are etting skipped and i…
2
votes
5 answers

Synchronize writing to log in a multi-threading process

I implemented a Logger, so it can be used like ostream. e.g, if someone wants to write to the log - he can do something like this: LOG << "hello world " << 6 << 8.6 << "\n"; The log will be written to the screen, to log file, and to any other…
binyamina
  • 173
  • 1
  • 14
2
votes
5 answers

Using boost::mutex::scoped_lock inside const function

This code won't compile: class MyClass { boost::mutex _mutex; void foo() const { boost::mutex::scoped_lock lock(_mutex); //critical section } } But defining the function as non const…
Sanich
  • 1,739
  • 6
  • 25
  • 43
2
votes
1 answer

confusion over using upgradable lock on std::map's find/insert

Consider a thread-safe getter method in its,relatively, simplest form: std::map > repo; AAA & get(const std::string &key) { boost::upgrade_lock lock(repoMutex); std::map
rahman
  • 4,820
  • 16
  • 52
  • 86
2
votes
0 answers

Portable c++ boost::iterprocess::mutex, an another try

I was looking for long time around to have portable robust solution for multiprocessing synchronization. Who touche this things know that good solution are boost::iterprocess named sync objects. But .... When your process have named_mutex locked and…
2
votes
0 answers

Destruction of boost::mutex fails in class destructor

To begin: I have read many posts about the occurence of this error (e.g. boost::mutex::~mutex(): Assertion `!pthread_mutex_destroy(&m)' failed ) and as I can see they do not apply in my case. Additionally I can not use RAII as often suggested in…
Henkersmann
  • 1,190
  • 8
  • 21
2
votes
0 answers

boost::mutex::lock exception with error number 22

i am working with boost::mutex class to synchronize 2 threads on one resource. i get an exception when i call the following boost:mutex:lock() function: lock() { int const res=pthread_mutex_lock(&m); if(res) { …
Oded
  • 664
  • 2
  • 9
  • 30
2
votes
2 answers

Is there a boost equivalent to this "safe_read" call

I am new to boost threading (came from Win32 threading, which has probably ruined me). So I'm trying to make a more "RAII" way to check that the working loop should still be going. So I made this simple function: template T…
IdeaHat
  • 7,641
  • 1
  • 22
  • 53
2
votes
1 answer

Boost: Threading and mutexes in a functor

I'm trying something simple with threads and mutexes in C++ with boost. This is the code: #include #include class mutex_test { private: boost::mutex mut; public: void operator()() …
Mloc
  • 115
  • 1
  • 9