Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:35:34+00:00 2026-06-14T18:35:34+00:00

I am currently posting handlers to my io_service and execute them in a thread

  • 0

I am currently posting handlers to my io_service and execute them in a thread pool.

io_serv.post( boost::bind(&Class::bar, p1, p2) );

My workers run this function:

m_mutex.lock();
std::cout << "[" << boost::this_thread::get_id()
        << "] Thread Start" << std::endl;
m_mutex.unlock();

size_t tasks = m_serv.run();

m_mutex.lock();
std::cout << "[" << boost::this_thread::get_id() << "] accomplished "
          << tasks << " tasks" << std::endl;
m_mutex.unlock();

So far so good but now I want to trigger an event when the handler queue is empty without killing my active (but waiting) threads.

Is it possible and how ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:35:35+00:00Added an answer on June 14, 2026 at 6:35 pm

    First time i see using of asio as a queue dispatcher. Not bad technique i think.

    Well, i suggest you are running io_service::run to serve the handlers. As documentation says, run will block until io_service is stopped OR all work has finished. So you can run your “empty queue event” after io_service::run:

    while( !finished ) {
        io_serv.run();
        io_serv.reset();
        io_serv.post( boost::bind(&Class::fill_queue, instance) );
    }
    

    This in case you have no other asio activity on this io_service and you not using io_service::work.

    As mentioned in comments you using io_service::work so plan A failed(it will not work since this class prevents exitting on empty queue). Well, you can do io_serv.post() after each bunch of io_serv.post()-s for thread jobs. The handler can contain waiting with boost::condition while other threads finish their work. As you do post() for this after actual jobs, i think asio will call it after dispatching all jobs, but its subject for investigation. Anyway that handler can re-post() himself to free current thread if condition is not ready yet.

    But i think easiest way is to replace io_service::work with equialent while construct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Comment box is not hiding after posting any thing. currently using AJAX to post
Im currently posting some data to a php webservice using a class that extends
I need jQuery to post to a relative url (currently its posting to the
I am building timeline posting for a fantasy trading company. Currently the ticker displays
My problem is the following: I'm posting a notification to the notifications bar, and
I have a simple form that I am currently posting back to the server
I'm currently in the process of writing a little blog / generic posting system
I'm posting a json request to server. I can see the http post is
I have some legacy application that are currently posting basic information to a MVC3
I'm currently writing a posting website that needs to have a version control on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.