Thread: "_beginthreadex()" vs. "CreateThread()"

  1. #1
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64

    Question "_beginthreadex()" vs. "CreateThread()"

    Hi,
    I would like to build some multi-threaded application but I have read on other pages, that there are two "rival" functions for creating a thread: "_beginthreadex()" and "CreateThread()".
    I am confused now because I don't know which one is better to use.
    Somewhere I have read that "CreateThread()" function is more low-level (so maybe it could be faster on Windows systems). But on other hand, using the second one "_beginthreadex()" is more safer (it prevents memory data from loosing).

    SO THE QUESTION IS:
    It is GOOD (or the best) to use only the "_beginthreadex()" function EVERYWHERE?


    Thanks.

    Petike

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you are ever going to call C library functions from your thread, you should use _beginthread(), as that sets up some per-thread data that is needed by the C library function. As far as I can tell, there would be little or no benefit from using CreateThread, unless you have a very good technical reason why _beginthread() won't work.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    There's no speed difference. _beginthreadex() simply does a little book-keeping and calls CreateThread().

    Just use _beginthreadex(). If you really want to understand the potential memory leak when not calling _beginthreadex() - http://cboard.cprogramming.com/showp...79&postcount=4

    gg

  4. #4
    Beginning game programmer Petike's Avatar
    Join Date
    Jan 2008
    Posts
    64
    OK,
    thank you both very much for answers.

    Petike

Popular pages Recent additions subscribe to a feed