Re: Trouble using DO for interthread communication
Re: Trouble using DO for interthread communication
- Subject: Re: Trouble using DO for interthread communication
- From: Brendan Younger <email@hidden>
- Date: Fri, 22 Jun 2001 10:26:01 -0500
Wow! That's a lot of threads! I think you already answered your own
question when you mentioned that putting a while loop in threadRun:
cures the problem. In your current implementation, you're probably
interrupting NSLog() and then calling it again causing Bad Things To
Happen (tm). You could implement the lock test [lock tryLock] to make
threadRun: run atomically but it would probably be better in terms of
overhead to use a loop. Also, I don't like the fact that you initialize
the connection in a separate thread and then proceed to launch another
one that uses the connection (this probably causes at least one of those
errors). My suggestion for using threads: When you launch a thread
using DO, init the secondary thread with a run loop and send a message
to the main thread indicating that it is safe to message the secondary
thread. Then, when you need the secondary thread to do something,
message it and have it do its thing. Also, your example has a lot of
cases where the parent thread exits and leaves the child running. This
may or may not lead to trouble but it offends my aesthetic
sensibilities. I usually try to have a bunch of children off the main
thread (eases the task of quitting the app) and when you do have
children of children, make sure the child returns before the parent does.
Just my $0.02, hope I helped.
Brendan Younger