DO: threads deadlock when sending oneway messages to each other
DO: threads deadlock when sending oneway messages to each other
- Subject: DO: threads deadlock when sending oneway messages to each other
- From: Florent Pillet <email@hidden>
- Date: Wed, 9 Jun 2004 10:01:13 +0200
Hi all,
I have two threads that communicate through distributed objects. This
tends to work about right except when the flow of messages between
threads accelerate. I use (oneway void) messages most of the time, both
ways, to not have the processing flow too much slowed down. Following
other's recommandations, it seemed that (oneway) was a simple way to
get a request queue between two threads without having to resort to the
traditional queue/locks.
Here is what I see: Thread 1 sends a bunch of messages to thread 2.
Each message is a (oneway void) message, so they get queued on Thread
2's run loop. Thread 2 processes the message and sends a reply message
to thread 1, again using a (oneway void) message.
This works fine for a succession of messages but all of a sudden, the
code enters a deadlock. Thread 1 is blocked while sending the message
to thread 2, thread 2 is blocked in the message processing while trying
to send the reply to thread 1.
Here is a backtrace of the two threads:
Thread 1:
#0 0x900074c8 in mach_msg_trap
#1 0x90007018 in mach_msg
#2 0x90a059dc in +[NSMachPort
sendBeforeTime:stream
Data:components:to:from:msgid:reserved:]
#3 0x90a25e34 in -[NSMachPort
sendBeforeTime:stream
Data:components:from:msgid:]
#4 0x90a19a74 in -[NSConcretePortCoder sendBeforeTime:sendReplyPort:]
#5 0x90a03d48 in -[NSConnection sendInvocation:]
#6 0x909fcfd0 in -[NSObject(NSForwardInvocation) forward::]
#7 0x90836810 in _objc_msgForward
#8 0x0072a930 in -[SBDeviceController queryExtendedData:] at
SBDeviceController.m:193
-> Locked in: [server getExtended
Data:someArgs]
Thread 2:
#0 0x900074c8 in mach_msg_trap
#1 0x90007018 in mach_msg
#2 0x90a059dc in +[NSMachPort
sendBeforeTime:stream
Data:components:to:from:msgid:reserved:]
#3 0x90a25e34 in -[NSMachPort
sendBeforeTime:stream
Data:components:from:msgid:]
#4 0x90a19a74 in -[NSConcretePortCoder sendBeforeTime:sendReplyPort:]
#5 0x90a03d48 in -[NSConnection sendInvocation:]
#6 0x909fcfd0 in -[NSObject(NSForwardInvocation) forward::]
#7 0x90836810 in _objc_msgForward
#8 0x007a43b4 in -[SBServer getExtendedData:] at SBServer.m:367
-> Locked in: [client retrievedExtended
Data:myData]
So from what I see, there would be a lack of proper locking when
sending (oneway) messages between threads. If that is true, I'll have
to dump this scheme altogether and revert to good old message queue /
locking techniques, completely bypassing the DO mechanism.
Any idea?
--
Florent Pillet, Code Segment email@hidden
Developer tools and end-user products for Palm OS & Mac OS X
ICQ: 117292463
http://perso.wanadoo.fr/fpillet
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.