[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
NSConnection multi threading problem/bug
From: |
Wim Oudshoorn |
Subject: |
NSConnection multi threading problem/bug |
Date: |
Fri, 25 Aug 2006 17:10:15 +0200 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/22.0.50 (darwin) |
We use in our program DO to communicate between threads.
Now sometimes it happened that our application hanged and
stopped working. Unfortunately it is not very reproducable.
However recently we managed to make it more or less reproducable
and it turned out that roughly the following happens:
A auxiliary thread, which communicates with the main thread will exit
and a call
[NSThread +exit]
will take place. This in turn triggers a call to:
[NSConnection -_threadWillExit:]
which contains the following snippet:
M_LOCK (connection_table_gate);
enumerate over 'connection_table'
and on over 'connection' call:
[connection removeRunLoop: runLoo];
M_UNLOCK (connection_table_gate);
Now very infrequent but it sometimes it happens that the method
[NSConnection -invalidate]
is called while the connection is still valid. In that case we get to the code
snip-pit
M_LOCK (connection_table_gate)
NSHashRemove (connection_table, self)
M_UNLOCK (connection_table_gate)
Now this will block because 'connection_table_gate' is an NSLock.
Unfortunately I don't understand the whole DO system well enough to understand
why this happens.
But I have changed the method [NSConnection -_threadWillExit] to first make a
copy
of the hash table and afterwards iterate over the copy.
This solves our hangs.
Wim Oudshoorn.
nsconnection.patch
Description: Copy connections before removing runloop
- NSConnection multi threading problem/bug,
Wim Oudshoorn <=