Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Integrating TBB mutexes and Boost.Thread locks

andysem
New Contributor III
399 Views
Hi,
As you probably know, Boost.Thread provides a number of generic lock scope guard classes, such as lock_guard< T >,unique_lock< T >,shared_lock< T >,upgrade_lock< T > andupgrade_to_unique_lock< T >, where T is a lockable type. These classes assume presence of the specific member functions in T to perform locking, but some of these functions are not present in TBB mutexes. My current problem is withspin_rw_mutex, which does support shared and upgradable locking but with a different interface. Other TBB mutex types also provide locking with different interfaces, and what's most frustrating is that different mutex types provide same locking functionality through different interfaces (e.g. queueing mutexes have no methods at all).
Could it be done that all TBB mutexes provide the same interface for each particular type of locking, preferably compatible with Boost locks? I realize that in case of queueing mutexes this would not be trivial, I can only think of specializing lock types for these mutexes. These specializations could be placed in a separate header withing compat directory. For other mutexes it seems to suffice to add the required synonym methods for the existing ones (e.g. lock_shared forwarding to lock_read inspin_rw_mutex).
0 Kudos
6 Replies
andysem
New Contributor III
399 Views
No comments about this? I could submit a patch if there is interest, but I'd like to know beforehand before I start working on it.
0 Kudos
RafSchietekat
Valued Contributor III
399 Views
What would be the purpose?
0 Kudos
andysem
New Contributor III
399 Views
I thought it was obvious from my original post. I want to be able to use Boost locks with TBB mutexes. Aside from simplifying generic programming, Boost locks provide other features, such as move support, that I often use.
0 Kudos
RafSchietekat
Valued Contributor III
399 Views
That's rather vague, I'm afraid. It does surprise that boost does not seem to provide a spin mutex (I just had a look at the documentation), but wouldn't an adapter be fairly trivial to write? I guess if you need it, you'll write it, and then the code will explain itself, even if it's not comprehensive yet.

Be aware, though, thatlocks are often not the best way to synchronise tasks (except very briefly), and they will sometimes lead to deadlock because of how the TBB schedules tasks, so it may be better to express additional task dependencies instead.
0 Kudos
andysem
New Contributor III
399 Views
Of course, I could write wrappers around different TBB mutexes to unify their interfaces, in fact this is what I do, currently. It just seems to me that the need for such scaffolding indicate that the interface of the library is flawed.
BTW, I don't use TBB solely for its task scheduling mechanism. In fact, most of my use cases only involve concurrent containers and mutexes.
0 Kudos
RafSchietekat
Valued Contributor III
399 Views
Whether it's flawed (and which side...) or justdifferent, without details I'll have to abstain from further discussion.
0 Kudos
Reply