Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2004-09-06 05:20:02

>I am not sure I understand it well, so let's try with a concrete example of
>FIFO queue.
>Let's say you are asynchronously receiving message blocks (not necessarily
>of fixed size) and you implement that with two threads:
>- one is accumulating data until message end is found and puts the block in
>the queue
>- another reads and parses message blocks
>At this point the chunkiness of the data and the fact that data for message
>blocks arrive asynchronously is modelled via element membership in the queue
>container which must be accessed in a thread-safe manner.
Use mutexes.

>Thread-safe queue (whether lock-free or using 'ordinary' locks on all
>accessors) seems a way to implement this without programmer
>having to explicitly consider threading issues. One programmer puts the data
>block, another picks them and parses them.
In my experience, I hardly need just a container to be thead-safe. I
usually need more data in addition to the container (which needs to be
thread-safe). For instance, an extra latest_access_time, out_file,
used_for_the_first_time, etc.

Thus, to me, the benefit of having a thread-safe container is very small.


John Torjo
-- john_at_[hidden]
Contributing editor, C/C++ Users Journal
-- "Win32 GUI Generics" -- generics & GUI do mix, after all
-- v1.3beta released - check out splitter/simple_viewer, 
   a File Explorer/Viewer all in about 200 lines of code!
Professional Logging Solution for FREE
-- (logging           - C++)
--         (viewing/filtering - Win32)
--        (debugging         - Win32)

Boost list run by bdawes at, gregod at, cpdaniel at, john at