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

Re: Thread pooling vs. AfxCreateThread() vs. beginthreadex...

249 views
Skip to first unread message

m

unread,
Mar 26, 2006, 8:46:58 PM3/26/06
to
In general it is not a good idea to use MFC in any app that you think you
need a thread pool (the WIN32 API kind) in.

The CRT auto initializes itself as necessary. The only hazard of this a
small memory leak on thread termation (you can prevent this by calling the
CRT cleanup code manually) which is only important of you create / distroy
many threads.

"Joseph Galbraith" <Joseph.G...@nospam.nospam> wrote in message
news:73DB19D4-8D48-41FC...@microsoft.com...
> When using MFC, one must use AfxCreateThread() so that
> MFC gets a chance to setup the thread.
>
> If one is going to use the C RTL but not MFC, one uses beginthreadex
> instead, to let the C RTL initialize the thread.
>
> Presumably, thread pooling functions are not using either one of these
> functions to create threads...
>
> Do my question is this: does this cause problems? If so, is there a
> work-around?
> If not, why not?
>
> Thanks,
>
> Joseph


Skywing

unread,
Mar 26, 2006, 8:57:01 PM3/26/06
to
Also, if you link to the DLL version of the CRT (which I would recommend in
most cases), you don't have to worry about this as MSVCR*.dll's DllMain will
free the appropriate structures on DLL_THREAD_DETACH indications.

"m" <m@b.c> wrote in message news:ujvAXBUU...@TK2MSFTNGP12.phx.gbl...

Arkady Frenkel

unread,
Mar 27, 2006, 2:59:23 AM3/27/06
to
Hi!
"Eugenio Mir?" <Eugen...@discussions.microsoft.com> wrote in message
news:7C3D6971-A387-45C6...@microsoft.com...
> There is a third function to create threads, in fact AfxCreateThread
> internally uses it. This is CreateThread.

But that not CreateThread() API important to mention , that
CWinThread::CreateThread() which called beginthreadex but only some
some setup and synchronization ( look at thrdcore.cpp of MFC sources ) , so
opposite to Win32 in MFC there is strongly not recommended to call
beginthreadex directly but through AfxBeginThread() only.
If you are in Win32 world the guys already answered you , but you can read
additionally full answer when and how to use both in Win32 world in
http://www.microsoft.com/msj/0799/win32/win320799.aspx

BTW that one of the features I like in Windows CE there is no head-ache of
thread functions ( no CRT ),so CreateThread is the only option :)

>
> I dont understand very well your question, What kind of problems are you
> talking about, mixing creating thread methods?, using C runtime with
> diferent
> methods? usingo MFC with ?
> Explain yourself better so we can help you better :)

That really interesting what is the problem :)

Arkady

Arkady Frenkel

unread,
Mar 27, 2006, 3:17:53 AM3/27/06
to
BTW I checked that on new MFC ( ATL MFC of new Visual Studios ) and code
didn't change too
Arkady

"Arkady Frenkel" <ark...@hotmailxdotx.com> wrote in message
news:uhYxpRX...@TK2MSFTNGP10.phx.gbl...

Alexander Grigoriev

unread,
Mar 27, 2006, 10:55:33 AM3/27/06
to
What memory leak are you takling about?

"m" <m@b.c> wrote in message news:ujvAXBUU...@TK2MSFTNGP12.phx.gbl...

chpichaud

unread,
Mar 27, 2006, 11:08:43 AM3/27/06
to
MFC can be used in thread pool, there is no problem about it. The
question is : do you need MFC in that kind of programming. ATL Server
has been built to answer thoses questions. ATL Server brings
CThreadPool Class <<This class provides a pool of worker threads that
process a queue of work items.>> . ATL Server is superior by design.
Consider it.

Ok you can design your own thread pool, your own thread mecanism, but
was is the cost. Do you think it will be better (perfomance/design).

When I need to code quickly, I reuse the ATL Server templates. There
are very smart to use.

Hope it helps.

Regards, Christophe Pichaud.

Skywing

unread,
Mar 27, 2006, 11:22:12 AM3/27/06
to
Memory is leaked if you use CreateThread/ExitThread and aren't using the DLL
CRT - specifically, the CRT PTD (per thread data) structures don't get freed
in that case because you don't use _endthread/ex and the DLL CRT isn't
managing the deletions in DLL_THREAD_DETACH.

"Alexander Grigoriev" <al...@earthlink.net> wrote in message
news:ezzKjbbU...@TK2MSFTNGP14.phx.gbl...

m

unread,
Mar 27, 2006, 6:25:56 PM3/27/06
to
As far as I can tell, the OP is talking about using the WIN32 thread pool
functions. This, necessicarily, negates the use of ALT thread pooling (at
leat for the same thing).


"chpichaud" <christop...@hotmail.com> wrote in message
news:1143475723.5...@j33g2000cwa.googlegroups.com...

0 new messages