Re: Threads with MFC
(I reply to all messages here)
Thanks, really helps - good to get confirmation, ... now I can start to
program this. And I agree what you say about doing postmessages (if there is
no other way...).
"Joseph M. Newcomer" <firstname.lastname@example.org> wrote in message
Now, to work with a thread, you must work with a static function, e.g.,
Yes, this is what I wanted. Have not tested, but seems like the solution. I
should have understood this myself.. :). Of course static could work. I will
Note that the way I work, I would never wait for the thread, I would have
no mutexes, and
no synchronization. Whatever data the thread is reading will simply not
be accessed until
the thread has completed, and it would irresponsible to try to do so. So
I arrange things
so that until the thread completes, and sends an asynchronous notification
cares about this completion, I do not touch the data from any other
thread. That way, no
synchronization is required (I consider the introduction of mutexes and
as demonstrations that the design is a failure)
Sounds logical, thats how I was also thinking.
Do not pop up message boxes in threads. In fact, do NO GUI interaction from
Sorry, I was just testing something, this does not belong to real code.
Doesn't seem to be much point to creating a thread that simply overwrites
its object value
then deletes the object. There is no reason to delete the object in the
Yes. I forgot to mention, this was just quick testing - I will not do that
on real code.
I have another question about passing a pointer to non-dynamical variable
instead of pointer to dynamical variable:
// OLD VERSION: A* a = new A;
//OLD VERSION: AfxBeginThread(MyThreadProc, a);
Can I pass object like this or it has to be dynamically allocated? The
reason I an hesitating is because if I do "A a" then the thread functions
UINT MyThreadProc( LPVOID pParam )
A* pObject = (A*)pParam;
(what i use to verify the object is correct) crashes. I dont really
understand why that crashes - it should point to correct memory address. It
works with dynamically allocated version.