Differences between createthraed/_ beginthreadex/afxbeginthread)

Source: Internet
Author: User
(1) createthread Function

Createthread: it is a Windows API function (standard form of SDK function, straightforward creation method, which can be used in any situation), and provides operations for creating threads at the operating system level,AndLimited to worker threads. Createthread can be used when you do not call MFC or RTL functions. Do not use it in other cases..Because:

In C RuntimeMultithreading is requiredRecord and initializationTo ensure that the C function library works properly.
MFCYou also need to know how to create a new thread.InitializationWork.

Some CRT functions include malloc (), fopen (), _ open (), strtok (), ctime (), or localtime ().SpecialData blocks locally stored by threads, ThisData blocks usually need to be created when a thread is created.,If createthread is used, this data block is not created.,The function will create one by itself and associate it with the thread. This means that if you use createthread to create a thread and then use such a functionOne piece exists and is created without knowing itAnd these functions are not deleted,And createthread and exitthread cannot know about it.So there will be memory
Leak (Memory leakage) will consume system memory resources sooner or later in software with frequent thread startup.


(2) _ beginthreadex Function

_ Beginthreadex: Extended SDK function of MS for C Runtime library,First, we initialize the C Runtime Library to ensure that the C Runtime Library works normally. Then, call createthread to create a thread.


(3) afxbeginthread Function

Afxbeginthread: the MFC function created by the thread in MFC. First, the corresponding cwinthread object is created, and then cwinthread: createthread is called. In cwinthread: createthreadInitialize the thread object. Then, call _ beginthreadex (afxbeginthread is safer) to create a thread.. It makesA thread can respond to messages and be used by interface threads or worker threads.


Note:

Afxbeginthread: In MFC, the worker thread/interface thread
_ Beginthreadex: it is used to call the C Runtime Library, but cannot be used in MFC.
Createthread: The worker thread, which cannot be used in MFC and cannot be used in C runtime. So it is best not to use it at any time.
Afxbeginthread_beginthreadexcreatethread

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.