Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost::asio::serial_port] Calling cancel() causes Run-Time Check Failure #0 on Visual Studio 2010 SP1
From: Igor R (boost.lists_at_[hidden])
Date: 2012-03-15 11:24:06


> It definitely helps; it crashed 0 out of 10 times, which is enough for me
> (it crashed every time before, even without traffic). I didn't know asio
> objects weren't thread-safe.

It's explicitly stated in the docs:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/reference/serial_port.html
(Look at the page footer.)
But in this particular case, the problem certainly was CancelIo issue,
rather than thread-safety one.

> I need to use them in a multithreaded environment; I have a reader and a
> writer thread. I suppose that wrapping every call to the serial_port object
> inside a post message would avoid any trouble but might be too slow. Am I right?

No, i don't think it would be slow, I believe the i/o itself would be
*much* slower. But in any case, making "premature optimizations" is
usually a bad idea. After you profile your application performance in
a real-life scenario -- you'll be able to see where the bottlenecks
are and to resolve them.

> Are there some general guidelines I should follow when using asio objects in multithreaded environments?

You can find the most useful approaches in asio tutorial and examples:
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/tutorial.html
http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/examples.html


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