Click to See Complete Forum and Search --> : AfxBeginThread() or _beginthread()


Mirsad
May 23rd, 2006, 05:04 AM
Hello comunity,
what funktion is to use in a MFC application, AfxBeginThread() or _beginthread()?
They are worker threads.

What is the better solution to make a application faster?
in my case i open a many files and read them, i start any workerthread with
AfxBeginThread() but i need more speed for my program!


With best regards
hm

sirikrishnap
May 23rd, 2006, 07:36 AM
In MFC, using AfxBeginThread is more sensible as it provides all the checks if anything goes wrong while creating. beginthreadex provided raw power. However, your speed improvement will come primarily from how you design your thread function.

philkr
May 23rd, 2006, 09:06 AM
You have to use AfxBeginThread()!
MFC requires certain internal state be set up properly for its correct functioning in a multithreaded environment. This includes creating (and upon completion, destroying) the per-thread handle maps. If you use these methods, you bypass MFC's maintenance of its internal state.

If you call no MFC functions from within the thread, and use no MFC objects in any form, you might get away with using _beginthread, _beginthreadex or CreateThread. But that means that using any MFC function inadvertently opens you to potentially fatal problems. Since there is essentially no reason to use these, you should use only AfxBeginThread.

Mirsad
May 24th, 2006, 02:49 AM
Hello,
thank you for answers, ok, i use AfxBeginThread(); !!


regards
mirsad

Naumaan
May 24th, 2006, 06:03 AM
but i need more speed for my program!Furthermore if u change thread priority to high level then it can be helpfull to gain more speed. Check MSDN for SetPriorityClass and SetThreadPriority APIs . It may helps u.

Siddhartha
May 24th, 2006, 02:41 PM
The implementation of AfxBeginThread uses _beginthreadex via CWinThread::CreateThread.

So, in both cases, you actually end up using _beginthreadex... ;)