Boost.Threads, Boost.Interprocess, mutex

Hello, In a single process but multithreaded software, should I use Boost.Threads synchronization mechanisms or can I use Boost.Interprocess synchronization mechanisms without counterparts and without seeing any difference ? ( in particular boost::interprocess::interprocess_semaphore class ) When using interprocess_mutex, my programm threw a lock_exception. I changed to boost::mutex and didn't managed to reproduce it. So, could this be related or the lock_exception has same chances to happen with boost::mutex ? I'm using semaphore to synchronize threads, so is it reliable in a single process multithreaded software ? By the way, I'm currently using boost::mutex instances which I lock() and unlock() directly. What benefits could I have by using boost::unique_lock (with a deferred lock) rather than access directly to the mutex instance ? Thanks in advance. Axel

Axel wrote:
Hello,
In a single process but multithreaded software, should I use Boost.Threads synchronization mechanisms or can I use Boost.Interprocess synchronization mechanisms without counterparts and without seeing any difference ? ( in particular boost::interprocess::interprocess_semaphore class )
In theory, you could use Boost.Interprocess, but those are prepared for shared memory and not optimized for a single process inter-thread synchronization. I would recommend using Boost.Thread.
When using interprocess_mutex, my programm threw a lock_exception. I changed to boost::mutex and didn't managed to reproduce it. So, could this be related or the lock_exception has same chances to happen with boost::mutex ?
I don't know, you could use catch that exception and print what it says.
I'm using semaphore to synchronize threads, so is it reliable in a single process multithreaded software ?
It should be, but I think a more efficient semaphore could be built for Boost.Thread. I know some consider semaphores risky, but for many tasks (like drivers, or signals) it's the only mechanism allowed by the OS to notify events to other threads. Regards, Ion
participants (2)
-
Axel
-
Ion Gaztañaga