Multithread communication
Multithread communication
- Subject: Multithread communication
- From: "McLaughlin, Michael P." <email@hidden>
- Date: Wed, 3 Feb 2010 11:30:15 -0500
- Acceptlanguage: en-US
- Thread-topic: Multithread communication
In a multithreaded app using NSOperationQueue and targeting Leopard, I am
having an inordinate amount of trouble communicating the results of the
thread computations to the main thread which acts as an overall coordinator.
Specifically, I am getting obscure and sporadic crashes (about 10 percent of
the time), some citing bad access and others unknown but which seem to
suggest that things are being done when the threads can no longer do them
(or something akin to that). All of these crashes occur deep in the system,
not in my code.
The threads read data upon initialization but do not write to any structures
but their own. I have to pass these filled structures back to the main
thread upon completion. The last thing each thread does is
postNotificationName to the main thread saying that it is ready to return
lots of data which it does via an NSPointerArray
[ptr pointerArrayWithStrongObjects]
and dictionary. The object which collects the results has a function
getOpResults() which accesses the passed pointer.
I thought that this should all be correct but somehow it crashes, at times
immediately, at other times only when everything is done and, 90 percent of
the time, not at all! I have attempted various remedies, including a static
NSLock for getOpResults(), retaining the NSOperations for a while in the
main thread, using a dependent signal to say that all threads should be
finished, using a countdown int to say the same thing. So far, nothing has
solved the problem.
The debugger stops showing only assembly and setting a break in
malloc_error_break (cited in some crashes) doesn't seem to do anything.
[Possibly a spurious error location.]
Could someone recommend the "best" (most robust) way to pass back data from
threads to the main thread? Is there a good way to probe crashes such as
these? Right now, I cannot even tell where the error is really occurring.
Thanks.
--
Mike McLaughlin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden