Winsock Functions. Process Monitor. Windows Sysinternals: Documentation, downloads and additional resources. Introduction to Multi-threaded Code. Download no synchronisation example - 31 KbDownload critical section example - 9 KbDownload mutex example - 9 KbDownload event object example - 9 Kb Someone recently asked me what I recommend for synchronizing worker threads and I suggested setting an event. This person's response was that you could not do that since worker threads do not support a message pump (UI threads are required to support messages). The confusion here is that events and messages are different animals under windows. I have forgotten where I originally copied these examples, but I found them to be interesting because of their simplicity. If anyone is aware of the author of this code, I would appreciate hearing from you, so I can give him/her credit. Note there is considerable support for threads in MFC that is not covered here.
API's like _beginthread (a C runtime library call) would likely be replaced by MFC API's like AfxBeginThread in an MFC application. No Synchronization Critical Section Objects Mutex Objects. Writing a Multithreaded Win32 Program. Each thread has its own stack and its own copy of the CPU registers. Other resources, such as files, static data, and heap memory, are shared by all threads in the process. Threads using these common resources must be synchronized.
Win32 provides several ways to synchronize resources, including semaphores, critical sections, events, and mutexes. When multiple threads are accessing static data, your program must provide for possible resource conflicts. Consider a program where one thread updates a static data structure containing x,y coordinates for items to be displayed by another thread. If the update thread alters the x coordinate and is preempted before it can change the y coordinate, the display thread might be scheduled before the y coordinate is updated. A mutex (short for mutual exclusion) is a way of communicating among threads or processes that are executing asynchronously of one another. Win32 also provides Thread-Local Storage (TLS) to store per-thread data.