Boost logo

Boost :

From: Matt Hurd (matt_at_[hidden])
Date: 2002-11-05 23:46:19


Thanks for all the work you guys do. Gives life a little boost...

I'm getting a some untidy memory faults on a simple thread program using the
elegant boost thread library from the thread_development tag with VC7 on
process exit.

Might be related to this link warning...

Creating library Release/boost_thread_play.lib and object
tss.obj : warning LNK4217: locally defined symbol _on_thread_exit imported
in function "class std::vector<struct std::pair<int,void *>,class
std::allocator<struct std::pair<int,void *> > > * __cdecl `anonymous

This is from a rw_mutex.html example. The html is unfinished. I took the
example code at the bottom and cleaned up a few typos. You might like to
use it to replace the example in the code, see below.

The existing win32 mutexes use critical sections. I see there is some
support for shared memory in thread development. Would love to see some
policy perhaps for win32 mutexes so it would be possible to use a cross
process mutex, such as the win32 mutex object. This would be especially
useful for win32. Could see a whole bunch on interesting policy
possibilites for this library but I'm just a simple fellow...




#include <boost/thread/rw_mutex.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/detail/rw_lock.hpp>
#include <iostream>

boost::mutex io_mutex; // The iostreams are not guaranteed to be

class counter
    counter() : rwm(boost::sp_writer_priority) , count(0) { }

    int increment() {
        boost::rw_mutex::scoped_rw_lock scoped_rw_lock(rwm);
        return ++count;

    int get() {
        boost::rw_mutex::scoped_rw_lock scoped_rw_lock(rwm,
            return count;

    boost::rw_mutex rwm;
    int count;

counter c;

void change_count()
    int i = c.increment();
    boost::mutex::scoped_lock scoped_lock(io_mutex);
    std::cout << "write_count == " << i << std::endl;

void get_count()
    int i = c.get();
    boost::mutex::scoped_lock scoped_lock(io_mutex);
    std::cout << "read_count == " << i << std::endl;

int main(int argc, char* argv[])
    const int num_threads = 5;
    boost::thread_group thrds;
    for (int i=0; i < num_threads; ++i)


    return 0;

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