Announcement

Collapse
No announcement yet.

WaitForMultipleObjects

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WaitForMultipleObjects

    Working away from home for a few days and I'm miles from my own machines (and notes ). Quick question for the fastest help I know


    Got a program that starts two worker threads, mythread1 and mythread2, Both run and do a half a task each so they finish around the same time. From the help files I get the impression I can use WaitForMultipleObjects to continue execution of the main thread once they both return. How does it work? ie, what's the syntax? Currently I'm using a sleepy while/wend loop with Thread Status monitoring the two variables holding the thread ids, ie.

    Code:
    (main program)
            THREAD CREATE MyThread1(tc) TO e
            THREAD CREATE MyThread2(tc) TO f
            THREAD STATUS e TO a
            THREAD STATUS f TO b
            WHILE a=259 OR b=259
                SLEEP 5
                THREAD STATUS e TO a
                THREAD STATUS f TO b
            WEND
    (main program cotinues, hopefully when the threads have completed)
    Thanks in advance.
    Neil Croft (cissp)

  • #2
    Doc:
    Code:
    DWORD WaitForMultipleObjects(
      DWORD nCount,
      const HANDLE* lpHandles,
      BOOL bWaitAll,
      DWORD dwMilliseconds
    );
    Applied:
    Code:
      REDIM    hThread (1)
      THREAD CREATE MyThread1(tc) TO hthread(0)
      THREAD CREATE MyThread2(tc) TO hThread(1)
      WaitForMultipleObjects 2, BYVAL VARPTR (hThread(0)), %TRUE, %INFINITE
      'program continues here when both thread functions have completed
      THREAD STATUS hThread(0) to Result1   ' get thread functions' return codes
      THREAD STATUS hThread(1) to Result2 
      THREAD CLOSE hThread(0) to Dummy     ' done with handles
      THREAD CLOSE hThread(1) to Dummy
    More examples of WFMO in Source Code Forum:
    Waitable Timer Object Demo June 2005

    Terminate Worker Threads Using Windows Events (and Using Thread Local Storage) Demo Dec 23 2005

    GUI + Worker Thread + Abort Demo 11-24-07

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thank you Michael. Just what I needed.
      Neil Croft (cissp)

      Comment

      Working...
      X