Skip to content

Instantly share code, notes, and snippets.

@snaewe
Created November 25, 2011 15:38

Revisions

  1. Stefan Näwe renamed this gist Nov 25, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Stefan Näwe revised this gist Nov 25, 2011. No changes.
  3. Stefan Näwe renamed this gist Nov 25, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. Stefan Näwe created this gist Nov 25, 2011.
    20 changes: 20 additions & 0 deletions gistfile1.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    // Fixed example from: http://thisthread.blogspot.com/2011/04/multithreading-with-asio.html

    void run (int tNumber) // 1.
    {
    boost::asio::io_service svc; // 2.
    boost::thread_group threads;

    {
    std::auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(svc)); //3.
    for (int i = 0; i < tNumber; ++i) // 4.
    threads.create_thread (boost::bind (&boost::asio::io_service::run, &svc));

    svc.post(std::bind(jobOne, 2)); // 5.
    svc.post(std::bind(jobOne, 1));
    svc.post(std::bind(jobTwo, 500));

    //svc.stop (); // 6.
    }
    threads.join_all (); // 7.
    }