Example for boost shared_mutex (multiple reads/one write)?

1800 INFORMATION is more or less correct, but there are a few issues I wanted to correct. boost::shared_mutex _access; void reader() { boost::shared_lock< boost::shared_mutex > lock(_access); // do work here, without anyone having exclusive access } void conditional_writer() { boost::upgrade_lock< boost::shared_mutex > lock(_access); // do work here, without anyone having exclusive access if (something) { … Read more

Weighted random numbers

There is a straightforward algorithm for picking an item at random, where items have individual weights: 1) calculate the sum of all the weights 2) pick a random number that is 0 or greater and is less than the sum of the weights 3) go through the items one at a time, subtracting their weight … Read more

How to use Boost in Visual Studio 2010

While Nate’s answer is pretty good already, I’m going to expand on it more specifically for Visual Studio 2010 as requested, and include information on compiling in the various optional components which requires external libraries. If you are using headers only libraries, then all you need to do is to unarchive the boost download and … Read more

Why do I need strand per connection when using boost::asio?

The documentation is correct. With a half duplex protocol implementation, such as HTTP Server 3, the strand is not necessary. The call chains can be illustrated as follows: void connection::start() { socket.async_receive_from(…, &handle_read); —-. } | .————————————————‘ | .—————————————–. V V | void connection::handle_read(…) | { | if (result) | boost::asio::async_write(…, &handle_write); —|–. else if … Read more