The core object of MFC multithreaded programming
Event, Mutex, Semaphore, file, file-mapping, process, thread
The first three are used for synchronization of threads.
(1)
Process operation: CreateProcess (); TerminateProcess (); ExitProcess ();
Thread operation: CreateThread (); ExitThread () is mainly called by the system, and TerminateThread () thread is forced to terminate it, too diabolical, and less good.
(2) The difference between criticalsection, Mutex, Semaphore, event
CriticalSection Critical Zone: EnterCriticalSection (), leavecriticalsection (); Mainly in order to protect the data, must appear in pairs, in-process use, thread exclusive data.
Mutex mutexes: CreateMutex (), OpenMutex (), ReleaseMutex (), WaitForSingleObject (), and WaitForMultipleObjects (), creating mutex handles, Can be called across processes, and threads monopolize data.
Semaphores Signal Volume: CreateSemaphore (); ReleaseSemaphore (); Similar to PV operation, OpenSemaphore (); WaitForSingleObject (); WaitForMultipleObjects (); Can span processes, can be used synchronously by multiple threads, and cannot exceed the maximum number of semaphores.
Event: CreateEvent (); OpenEvent (); SetEvent (); WaitForSingleObject (); WaitForMultipleObjects (); Can be synchronized across process data, no signal when running state, signal when exiting state. You can use WaitForSingleObject (), WaitForMultipleObjects () to wait for processes and processes to exit.
Threads encountered during C + + development (ii)