Boost logo

Boost Users :

Subject: [Boost-users] Making my UdpConnection class thread safe
From: Chris Dunphy (rc.dunphy.mlists_at_[hidden])
Date: 2012-04-30 16:31:08


I have implemented some connection classes, using Boost ASIO, to replace
some low level C code in an application, and everything is working great,
except for one problem.

Basically, I have a UdpConnection class that does synchronous read and
write, but it uses async methods to handle time-outs as per the boost
examples. The problem is I can't figure out how to make it threadsafe.

I have tried adding strands to the event handlers to make this class
threadsafe (code below), but that isn't working. I suspect it is because
of the way timeout is implemented. I have included my code in 4 classes in
pastebin.

Single threaded is working fine. I also have TcpConnection and
UnixSocketConnection classes that don't need to be shared amongst multiple
threads and they work fine. However, I can't get multi-threaded UDP code
to work.

Am I missing something? Sources below:

* Connection.h && AsioConnection.h http://pastebin.com/Cbbw37gL
* UdpConnection.h && UdpConnection.cpp http://pastebin.com/VLnHBnPs



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net