Original Post
Hi! I was wondering how I could use mutexes on a multi-threading application. I'm new on Multithread, tryied to use MUTEX to syncronize the execution of two threads, but all I got were some good headaches.
Look how I'm creating two threads and the mutex:
mtx = CreateMutex(NULL, FALSE, "ldskjfjoewrwoiru"); CreateThread(NULL, 0, &threadtest, NULL, 0, &tid); CreateThread(NULL, 0, &threadtest1, NULL, 0, &tid1);where mtx, tid and tid1 are declared as HANDLE. Before these code I have threadtest and threadtest1 functions declared as these:
DWORD WINAPI threadteste(LPVOID dfdf) {
if (WaitForSingleObject(mtx, 100) == WAIT_OBJECT_0) {
MessageBox(AppHandle, "Thread 01", "", MB_OK);
SetEvent(mtx);
}
}
DWORD WINAPI threadteste1(LPVOID dfdf) {
if (WaitForSingleObject(mtx, 100) == WAIT_OBJECT_0) {
MessageBox(AppHandle, "Thread 02", "", MB_OK);
SetEvent(mtx);
}
}
But when I compile and run my application, only one thread is acessed.
Where is the problem? Do you know a good documentation about this on the internet (not MSDN, because I have already searched there).
Thank you.
[edited by - FERNANDO-BRASIL on April 20, 2004 3:11:07 PM]