Warning: Private methods cannot be final as they are never overridden by other classes in /customers/d/5/f/rurandom.org/httpd.www/justintime/includes/actions/Action.php on line 82 Difference between revisions of "Boostcon 2011" - Just in Time
 Actions

Difference between revisions of "Boostcon 2011"

From Just in Time

Line 38: Line 38:
 
* First: single threaded
 
* First: single threaded
 
* Use other thread to handle long running task. Uset ''post'' to give the result back to the main thread. Take care to tell the service that there is still work pending while the background thread is working. use 'asio::ioservice::work''.
 
* Use other thread to handle long running task. Uset ''post'' to give the result back to the main thread. Take care to tell the service that there is still work pending while the background thread is working. use 'asio::ioservice::work''.
 +
* multiple io_services. Tip: If you want to make handlers wait for some event triggered by another async op, use a timer that will never expire.

Revision as of 16:25, 16 May 2011

This page will contain my notes taken during Boostcon 2011

Library in a Week

Review tools

  • Code Collaborator
  • Crucible (Crubicle?)

Boost.Asio

Chris Kohlhoff

fundamental concepts that went into the library. Use them in your programs.

One key criterium: should not be a framework, but a toolkit. This gives you more freedom.

io_service
"your channel into the operationg system"

Challenges of asynchronous programming:

  • Object lifetimes
  • Thinking asynchronously
  • Threads
  • ?

Object lifetimes

handlers and buffers are taken by value, a copy is made. Buffers are shallow.

Arguments taken by non-const reference: caller needs to guarantee lifetime. this-pointer should outlive operation. Newby problem: providing a buffer that goes out of scope (local variable for instance).

Use shared_ptr and shared_from_this to automatically manage object lifetime.

Thinking Asynchronously

Wrong:

if (socket.connected())
{   
    socket.write();
}

Threading

  • First: single threaded
  • Use other thread to handle long running task. Uset post to give the result back to the main thread. Take care to tell the service that there is still work pending while the background thread is working. use 'asio::ioservice::work.
  • multiple io_services. Tip: If you want to make handlers wait for some event triggered by another async op, use a timer that will never expire.