在 2019/5/7 上午6:17, David Mathog 写道: > Changed the called routine to (see below): > > DWORD RunCommand( void *lpParam ){ >
Insert an `__stdcall` before `RunCommand`. The calling convention is part of the function type. >> >>> 2. when run procs is shown as -1, not sure how that happens. >> >> Use `WaitForSingleObject()` to await **every** thread in a loop. Do not >> use `WaitForMultipleObjects()` as it has a upper limit of number of >> handles to wait for, and the return value is hard to handle properly (as >> you already did that wrong). > > You lost me. WaitForSingleObject() will only wait on a single handle at > a time. There might > be 20 subprocesses running, each with its own handle. A function is > needed which will return > when the first of those exits. Would that not be > WaitForMultipleObjects()? Even if it will > only work for lets say the first 16 processes, hopefully once those exit > the invisible ones > would slide into view? Or maybe it doesn't work that way? > If a thread terminates then its state becomes signaled; if you wait for it a second time then the wait function returns immediately stating that it is signaled. To mimic the POSIX `wait()` or `pthread_join()` behavior, for each signaled thread, you have to close its handle and remove it from the wait list for the next `WaitForMultipleObjects()` call. If I were you I would just write a loop that awaits ALL threads for 100ms. When the wait function returns, data can be copied from pipes to the standard output. The loop terminates only when all threads exit, whose handles are closed after the loop. -- Best regards, LH_Mouse
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public