Boost logo

Ublas :

Subject: Re: [ublas] vector / matrix thread write access
From: Vardan Akopian (vakopian_at_[hidden])
Date: 2010-08-31 13:06:28


I'm not sure what you're calling "a write lock". The "read-write lock"
I mentioned is a special type of lock where concurrent reads don't
block but writes block (and one of them has priority).
I'm guessing that's not what you mean, and I'm guessing you have a
simple lock on write access. If it's guaranteed that your reads will
happen after all the writes have finished, then you don't need anymore
locks on reads. However, if reads and writes can happen concurrently,
then you need to lock both reads and writes. Note that almost any kind
of modification to the container (such as insert, resize, any other
operation that may reallocate the internal memory, etc) should be
considered "a write" and should also be protected. And if the reads
can happen concurrently with these types of modifications then they
also need to be protected.

On Tue, Aug 31, 2010 at 2:21 AM, Kraus Philipp
<philipp.kraus_at_[hidden]> wrote:
> Hi,
>
> thanks for the answer, but need I a read-lock?
> I have got a empty ublas vector and every thread creates a write lock
> writes the data in a element and unlocks. After the data is in the vector
> every thread can read, but no thread must change it.
>
> I'm a little unsafe that I need both locks
>
> Thanks
>
> Phil
>
>
> Am 31.08.2010 um 02:57 schrieb Vardan Akopian:
>
>> uBlas containers are definitely not thread safe, so you need to
>> implement your own synchronization, by keeping a lock (possible a
>> read-write lock) when accessing the container. You could use the Boost
>> Thread library for that purpose.
>>
>> On Mon, Aug 30, 2010 at 6:54 AM, Kraus Philipp
>> <philipp.kraus_at_[hidden]> wrote:
>>>
>>> Hi,
>>>
>>> I use a ublas::vector for caching some data between threads. One of my
>>> threads sould write data into a position of the vector and the other
>>> thread
>>> should be read the data. In some cases more than one thread can write to
>>> the
>>> vector on the same position. Every thread that sets the data creates the
>>> same data, so it is irrelevant which thread writes.
>>>
>>> Are ublas::matrix and ublas::vector for reading and writing on the same
>>> indexposition thread-safe?
>>> If they are not, how can I make them thread-safe?
>>>
>>> Thanks
>>>
>>> Phil
>>> _______________________________________________
>>> ublas mailing list
>>> ublas_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>>> Sent to: vakopian_at_[hidden]
>>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: philipp.kraus_at_[hidden]
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: vakopian_at_[hidden]
>