Difference between beginthreadex and createthread

Source: Internet
Author: User

 

The thread may be very advanced for beginners, which is understandable. For some experienced programmers, it may be too simple. I think that people who think the thread is very simple do not understand the thread. There are too many things involved in the thread, including memory and initialization, thread synchronization. I plan to write this article in the form of QA.

      Q: Why should I replace createthread with _ beginthreadex?

A: Well, the comrades who have been using API createthread to create a thread should pay attention to it. You may say that I have been using this API to create a thread, and there is no problem at all. If so, I can only say that you are lucky. Inside _ beginthreadex, it calls createthread to create a thread, while windows always uses createthread to create a thread. Before calling createthread, beginthreadex performs a lot of initialization work, so it is safer than the thread created by createthread.

      Q: Why do we use two functions with the same function to treat single-thread and multi-thread sequential programs?

A: There are some historical reasons. The library of the Standard C language was invented around 1970. At that time, the concept of thread had not yet appeared in any operating system. However, the thread appears after all. Let's take a look at the following example to illustrate why the previous CRT does not support multithreading:

BOOL fFailure = (system("NOTEPAD.EXE README.TXT") == -1);        if (fFailure)       {               switch (errno)              {              case E2BIG:                     // Argument list or environment too big                      break;               case ENOENT:                      // Command interpreter cannot be found                      break;               case ENOEXEC:                      // Command interpreter has bad format                      break;               case ENOMEM:                      // Insufficient memory to run command                      break;      

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.