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:
(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:

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