Threads encountered during C + + development (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.