]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/thread/example/mutex.cpp
1 // Copyright (C) 2001-2003
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #include <boost/thread/mutex.hpp>
8 #include <boost/thread/thread.hpp>
11 boost::mutex io_mutex
; // The iostreams are not guaranteed to be thread-safe!
16 counter() : count(0) { }
19 boost::unique_lock
<boost::mutex
> scoped_lock(mutex
);
32 int i
= c
.increment();
33 boost::unique_lock
<boost::mutex
> scoped_lock(io_mutex
);
34 std::cout
<< "count == " << i
<< std::endl
;
37 int main(int, char*[])
39 const int num_threads
= 4;
40 boost::thread_group thrds
;
41 for (int i
=0; i
< num_threads
; ++i
)
42 thrds
.create_thread(&change_count
);