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).
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.
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.
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.