I'm just wondering if (and if so, how) it is possible to get the return value of a stream in C ++ (Windows). I have multiple threads and I use WaitForMultipleObjects(...) for them. This waits until the thread is executed, and returns the index of the specified thread, and everything will be fine. However, I want to be able to get the return value of a thread that has finished using its handle.
For instance:
DWORD WINAPI Thread1(void *parameter){ ... if(...) return 0; else return -1; } DWORD WINAPI Thread2(void *parameter){ ... if(...) return 1; else return 0; } int main(){ HANDLE t1 = CreateThread(0, 0, Thread1, NULL, 0, 0); HANDLE t2 = CreateThread(0, 0, Thread2, NULL, 0, 0); HANDLE *threads = new HANDLE[2]; threads[0] = t1; threads[1] = t2; int result = WaitForMultipleObjects(2, threads, false, INFINITE); if(result == 0){
I tried using GetExitCodeThread(thread) , but I assume this returns the system exit code, as it always gives me a very weird integer. Does anyone know a way or workaround?
source share