Processes Threads and Synchronization ===================================== Processes --------- CreateProcess - Creates a process ExitProcess - (use in C code) Terminates the process when called from one of the process threads TerminateProcess(hProc... - (use in C++ code) Terminates the process from outside (won't release any memory) GetCurrentProcessId GetCurrentProcess Threads ------- CreateThread - (Win32 API) Creates a thread _beginthread - (C Runtime) Creates a thread _beginthreadex - ... ResumeThread - Resumes the thread when it is suspended ExitThread - (use in C code) Terminates the thread when called from the thread itself TerminateThread(hThread... - (use in C++ code) Terminates the thread (won't release any memory) GetCurrentThreadId GetCurrentThread Synchronization --------------- Event (useful for inter-threaded communication) ----- CreateEvent - Creates a new event object OpenEvent - Opens existing event (using the event name) SetEvent - Signal ResetEvent PulseEvent - Tracks the event, after is was set, and releases it when all the threads recived it WaitForSingleObject - Used when a thread waits for a signal from a single object WaitForMultipleObjects - Used when a thread waits for a signal form an array of objects Critical Section (useful to protect data and functions from multithreaded access) ---------------- CRITICAL_SECTION cs; - The critical section variable declaration InitializeCriticalSection(&cs); - Initialize once EnterCtiticalSection(&cs); - May be used more then once for the same CRITICAL_SECTION variable LeaveCriticalSection(&cs); DeleteCriticalSection(&cs); - At the very end, when CRITICAL_SECTION variable is no longer required Mutex (Mutual Exclude) ----- Semaphor -------- ATOM (API Level Atomic Operations) ---- InterlockedIncrement - Controls a global variable (a synchronization flag) InterlockedDecrement - InterlockedExchange - InterlockedExchangeAdd - InterlockedExchangePointer - InterlockedCompareExchange - InterlockedCompareExchangePointer - ============================================ NOTES ======================================================== Speed: 1) It's faster to use global variables instead critical sections in a single process 2) Events are SLOW when used to synchronize between processes Signaling: 1) Signaled = free 2) Not Signaled = in use