WaitForMultipleObjects for Boost.Thread?

This is a discussion on WaitForMultipleObjects for Boost.Thread? within the C++ Programming forums, part of the General Programming Boards category; I've been looking into Boost's thread library for threading, but I cannot seem to find equivalent functionality for the WinAPI ...

  1. #1
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543

    WaitForMultipleObjects for Boost.Thread?

    I've been looking into Boost's thread library for threading, but I cannot seem to find equivalent functionality for the WinAPI WaitForMultipleObjects.
    My need is simple.
    I want to spawn n number of threads, and after having done so, wait until at least one of those threads have finished so that I can spawn additional threads.
    WaitForMultipleObjects is ideal for this purpose, but I can't seem to find any such functionality in Boost.Thread?
    Otherwise I would have to go polling every thread to see if they're finished and wait in-between (ie Sleep) making the solution non-portable.
    Any ideas?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,259
    Not all operating systems support functionality to wait on multiple threads. In fact, IIRC, it is an error under POSIX for a thread to join more than one other thread at a time.

    Rather than waiting for threads to finish so you can start new ones, why not have your thread functions simply go to their beginning once they have finished? All that is needed then is a means of signalling, or providing data protected by a mutex, so you can tell the thread what to do next.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    That might be an idea... A little more complex approach, but it might work.
    Yet, I find it silly that systems cannot wait on multiple threads to become signaled...
    Thanks anyway!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,181
    Some people find it silly that some systems can't fork(), too .

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Never needed fork
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by Elysia View Post
    That might be an idea... A little more complex approach, but it might work.
    Yet, I find it silly that systems cannot wait on multiple threads to become signaled...
    Thanks anyway!
    And I find it silly that some systems cannot wait on more than 64 objects...
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    That's silly, too. Theoretically it should be close to unlimited.
    Bad OS. Bad.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    2,361
    boost::threads has a class called thread_group.... you can add as many threads as you want to it and then call join_all() on it, and it will do exactly what you are asking for

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Not quite. I wanted to stop waiting as soon as one thread finished.
    But revamping the system, I'll always use the same amount of threads and let them share the data.
    However, I still have to wait for all threads to terminate before the main thread terminates, so this actually does come in handy!
    Thanks.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21