Threading issues encountered during C + + development

Source: Internet
Author: User

Multithreaded programming, there are different multithreaded methods under different programming languages or libraries.

such as PThread under MFC = AfxBeginThread (Mythread2, (LPVOID) this, NULL); Not very useful.

The following is the C + + standard library of multi-threaded programming methods, multithreaded programming is generally associated with the signal, through the signal to determine the thread start, suspend, restart, shutdown and so on.

There are several functions that are mainly

1. Create a signal Handle hevent = CreateEvent (null,true,true,null);

2. Create a thread Handle hthread = CreateThread (NULL, 0, Initthreadproc, this, 0, &m_dwthreadid);

3, SetEvent (m_hevent); set signal, signal status

4, ResetEvent (m_hevent); reset signal, no signal status

5. Dword dwstatus = WaitForSingleObject (m_hevent, INFINITE); Wait for a signal, ininite indefinitely wait until there is a signal to accept, return; If 0, return immediately.

6, Colsehandle (m_hthread);//close a thread.

7, GetExitCodeThread (M_hthread, &dwcode); Gets the exit code for a terminated thread, not 0 for success, 0 for failure, and GetLastError ().

The class can also set some parameters when the class's local variables are used by the class.

Basically, C + + multithreaded programming is so much, in short, the connection between thread and signal use, changeable.

Threading issues encountered during C + + development

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.