Boost logo

Boost Users :

Subject: Re: [Boost-users] [Intrusive] unordered_set and thread safety
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2012-11-21 16:14:53


El 18/11/2012 8:56, Alexandre Hamez escribió:
> Hello,
>
> I'm currently using intrusive:: unordered_set in a single threaded application. But now, I need to switch to a multi threaded application. As such, the unordered_set must be protected.
> I don't want to block the whole table with a single mutex. Thus, it would be fine to have a lock per bucket. Furthermore, intrusive:: unordered_set provides a bucket_traits mechanism to enable some customization.
> So, my question: is it possible to use bucket_traits to have a lock per bucket?

I don't think so. We can obtain the bucket from the value but there is
no insert function taking a bucket as argument. That would be an easy
way to get some paralelism, at least for insertions. Intrusive could
guarantee that the bucket search can be done in parallel and the
insert_in_bucket function could be called with a locked mutex.

We would need an erase_from_bucket function that does not return an
iterator to the next remaining object, as that could provoke race
conditions (the next remaining object can be in a different bucket).

It's an interesting optimization for Intrusive, but I'm afraid it's not
trivial.

Best,

Ion


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net