Boost logo

Boost Users :

Subject: [Boost-users] [ASIO] Thread safety of socket.write_some & socket.read_some
From: James12 (james791d_at_[hidden])
Date: 2008-10-29 08:50:02


I'm a beginner in using boost asio library (and coding c++ too :).

I am currently trying to code a simple application that handles some
communication with a server through TCP/IP connection.

My I/O Class has two threads that use synchronous socket operations on the
same socket (which is a member of the class)

Main thread:
- socket.close()
- socket.write_some(boost::asio::buffer(initial_command));
- socket.read_some(boost::asio::buffer(initial_command_reply));
CApplication::Write(data from another class)
- m_Socket.write_some

  - socket.read_some(boost::asio::buffer((void *)&character, 1));
  - package bytes to messages and pass them on to another class
while (!bClosed)

My question is that is it safe to call write_some and read_some from
different threads without synchronization.

The application is now working w/o problems but I need to be sure that this
is a safe way to do this before continuing development.

Thanks for your reply,

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at