Click to See Complete Forum and Search --> : Threads : AfxBeginThread() question
Hi,
If I have a second thread running, which I created by calling AfxBeginThread(MyThreadFunc,hWnd); And in MyThreadFunc (UINT MyThreadFunc(LPARAM))I want to create another thread. Can I use AfxBeginThread()? Doesn't this belong to one of MFC's classes (CThread or something)? Which classes can I NOT use inside MyThreadFunc()? If I can't call AfxBeginThread(), that what are my alternatives?
Thanks for your advice/help/time/samples!
Regards,
Anonymous.
BrianOG
June 1st, 1999, 10:19 AM
AfxBeginThread is a global MFC function, not enclosed within any class.
As are most (if not all) Afx.... functions.
In your first thread function, you can create another thread using AfxBeginThread and so on.
Just keep your eye open for problems with thread 2 exiting before thread 3 if you have any dependicies in there
Gee Thanks Brian!
Is it true that I can't use CWnd or any of it's base classes inside my thread function? What if I needed access to my View? or Document? etc. I thought that by passing a pointer to a class as the LPVOID param, I would have access, and can freely call on any data/functions of that class. Can I?
What if my thread needs access to 2 or more classes?
Yours,
Anonymous(friends call me Annie ;)).
BrianOG
June 2nd, 1999, 01:46 AM
If you want to pass more that one pointer to the thread, define a structure, create the structure in the main application, populate it, pass a pointer to the structure to the thread.
You can access anything you pass to the thread, but you got to be careful about not corrupting data. Look up AfxBeginThread in the VC help, and there should be some links to useful information about thread-safe programming.
Brian
ric
June 2nd, 1999, 07:11 AM
AfxBeginThread does not belong to any MFC class so go ahead be brave, use it and then report your investigation.
Another idea, create the second thread where you have created the first, but create it with CREATE_SUPENDED flag on, then by a global variable or message turn on the second thread.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.