[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Threads, DO and Runloop unexpected behaviour
From: |
Wim Oudshoorn |
Subject: |
Re: Threads, DO and Runloop unexpected behaviour |
Date: |
Tue, 01 Nov 2005 17:59:40 +0100 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) Emacs/22.0.50 (darwin) |
Richard Frith-Macdonald <richard@brainstorm.co.uk> writes:
> On 1 Nov 2005, at 14:54, Wim Oudshoorn wrote:
>
>>
>> I am using DO to communicate between threads.
>> In the following simple example we have 3 threads.
>>
>> - Worker thread, handling requests from thread A and B
>> - thread A performing -doInternal on the Worker thread
>> - thread B perfomring -doExternal on the Worker thread
>>
>>
>> Now the doExternal thread will wait until something happens
>> and in order to avoid blocking all other work, it will
>> explicitly run the runloop. So during execution of
>> -doExternal it should be possible that thread A gets its
>> requests for -doInternal processes. However, it sometimes does NOT!
>
> Well, the main (Worker) thread handles the requests, and two other
> threads make the requests.
> Since only one thread is handling requests, you can't have both
> running at the same time ... so the 'perfect' situation would be that
> you see calls to -doInternal and -doExternal alternating. However,
> chance and the system scheduler could do things differently ...
No, the -doExternal method will run the runloop again, so it is available
for handling the new -doInternal requests. Mostly this works fine
and while -doExternal is executing it will process -doInternal. However
once in a while it will fail.
This is unfortunate because in our, more complex case, this will
lead to a deadlock.
It is perfectly possible that I misuse the system, but I hope not.
Wim Oudshoorn.