Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Createthread vs. beginthread vs. createthreadex (newbie)

505 views
Skip to first unread message

Luis Pablo Prieto Santos

unread,
Oct 20, 2000, 3:00:00 AM10/20/00
to
Well, I'm making some multithreaded programming with C in WinNT, and,
after reading VC++ 6.0's "help" and other resorces, I don't know which
to use and why. Can anybody help me?
Thanx,
Luis

David Schwartz

unread,
Oct 20, 2000, 3:00:00 AM10/20/00
to

Use _beginthreadex, unless you're using MFC, in which case use
CreateThread.

DS

Tony

unread,
Oct 26, 2000, 7:28:41 PM10/26/00
to
If you're using the standard C/C++ library, then you have to use the
"beginthread" function because it sets up things like TLS to hold errno and
strtok variables. I don't see any reason to use anything but CreateThread if
you're strictly using the Win32 API in lieu of the ANSI library.

Tony

"Luis Pablo Prieto Santos" <lp...@tid.es> wrote in message
news:39F0621D...@tid.es...


> Well, I'm making some multithreaded programming with C in WinNT, and,
> after reading VC++ 6.0's "help" and other resorces, I don't know which
> to use and why. Can anybody help me?

> Thanx,
> Luis
>
>


johnso...@my-deja.com

unread,
Oct 28, 2000, 7:22:48 AM10/28/00
to
Supplementing the previous suggestion, it's generally preferable to use:

_beginthreadex() and _endthreadex()

rather than:

_beginthread() and _endthread()

Why?

1) _beginthreadex() has exactly the same parameters as CreateThread in
exactly the same order, simplifying the conversion.

2) There are problems with _beginthread() and _endthread() related to
how they can close the handle under certain circumstances, leading to
undesirable race conditions. The "ex" versions don't introduce these
considerations.

If you continue to use CreateThread, be certain that your thread
function does not call the C library and never will call it, directly
or indirectly.

When using _beginthreadex() in the VC++ environment, don't forget to
set the project settings to multithreaded. That is, starting from
"Projects" on the toolbar:
projects -> settings -> C/C++ tab -> CodeGeneration -> MT DLL

Johnson (John) M. Hart
jmh...@world.std.com


In article <J63K5.2253$5b4.1...@bgtnsc05-news.ops.worldnet.att.net>,


Sent via Deja.com http://www.deja.com/
Before you buy.

0 new messages