Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] serial_port question
From: Michael Caisse (boost_at_[hidden])
Date: 2009-08-26 12:16:05


Robert Dailey wrote:
>
> Would you recommend calling read_start() from its own thread and have
> it loop indefinitely? I believe this is what you originally suggested.
> However, I am curious about the issues with calling read_some() and
> write_some() from separate threads without using any external
> synchronization techniques (i.e. mutexes). Do I have to synchronize
> these two calls manually or is it done internally? I'll re-review the
> documentation, but I did not see anything regarding this earlier.
>
> Thanks for your help.

The io_service takes care of the "threading" issues for you. Just
call read_start once from (lets say) main to get the processes going
and then it all happens in the background... asynchronously. The
call to read_start doesn't block. If you want different threads
to operate on the io (though I recommend not doing this at first)
then you can use a thread pool to call the io_service.run method
from multiple threads.

Have a look at some of the examples to see how it is all put
together. Reading/writing to serial ports is the same as reading/writing
to sockets using asio. I like to recommend the chat server/client
example. It pulls together a lot of asio concepts in an easy to
understand application.

Michael

-- 
----------------------------------
Michael Caisse
Object Modeling Designs
www.objectmodelingdesigns.com

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