L
L
leanid2013-07-16 13:10:17
C++ / C#
leanid, 2013-07-16 13:10:17

How to correctly terminate a child thread that is waiting for an operation to complete?

Pseudocode of a child thread that waits for data and sends messages to the main thread upon receiving this data, how to terminate it correctly if the main thread has received a completion message? I feel a lack of knowledge, maybe something to read? In general, I use boost:: asio and I want cross-platform.

while(true)
    {
        some_monitor.async_monotor(callback_handler);
        io_service.run();
        io_service.reset();
    }

If I understand correctly, then io_service.run () - here I wait until the system notifies my thread and I have no other way to complete this, except to send data to myself (child thread) that will mean completion?
void callback_handler(data d)
    {
        if (d == STOP)
        {
            running = false;
        }
    }
...
    while(running)
    {
        some_monitor.async_monotor(callback_handler);
        io_service.run();
        io_service.reset();
    }

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SadGnome, 2013-07-16
@leanid

I don't remember exactly, but try calling io_service.stop() from another thread to interrupt the execution of run().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question