gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GWorkspace file operation pause/stop problems


From: Riccardo Mottola
Subject: Re: GWorkspace file operation pause/stop problems
Date: Thu, 18 Sep 2014 18:56:57 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0 SeaMonkey/2.29

Hi,

trying to fix futher the "stopping" of the operation after the "pause" of it, I follow up this analysis with a new wuestion.

DO and threads are involved, but the "executor" is instantiated where and released where? I understand it is "retained" in registerExecutor, but alloc'd in setPorts and thus created there (where it gets passed as an object to registerExecutor).

But release? I put an NSLog() in the executor dealloc, so by reasoning it gets leaked.

More than this, several part of the code work by testing if(executor) This works the first time perhaps, but never when the executor actually ended.

endOperation itself has this vicious check, but also sendDidChangeNotification.

Riccardo


Wolfgang Lux wrote:
Hi Riccardo Mottola,

Okay, processing is a bit obfuscated since it involves DO calls between the 
threads. I'll try my best to explain what happens when the code is run.

The auxiliary thread is started by calling
   [NSThread detachNewThreadSelector: @selector(setPorts:)
                            toTarget: [FileOpExecutor class]
                          withObject: ports];
in method FileOpInfo -startOperation. This means that the auxiliary thread will 
execute the FileOpExecutor +setPorts: method and finish as soon as that method 
returns.

Now turning to the +setPorts: method, it uses DO to call -registerExecutor: on 
the FileOpInfo instance on the main thread. So the code in the auxiliary thread 
now waits for the -registerExecutor: call on the main thread to finish and once 
that happens the auxiliary thread will terminate.

Next looking at the -registerExecutor: method, this uses DO again to call the 
-calculateNumFiles method on the FileExecutor instance. This call is going to 
be processed on the auxiliary thread while that thread is still waiting for the 
-registerExecutor: method to finish on the main thread. Yet, since 
-calculateNumFiles is (correctly!) declared as oneway method -registerExecutor: 
will not wait for -calculateNumFiles to terminate and just return immediately. 
So the main thread sends a reply back to the auxiliary thread which is still 
executing the -calculateNumFiles method. But once -calculateNumFiles returns, 
the DO call to -registerExecutor: on the auxiliary thread will return as well 
and hence the auxiliary thread will terminate.

So finally, we can look at -calculateNumFiles. At the end, this method calls 
-performOperation and the latter calls one of the -do... methods, e.g., 
-doMove. So if the loop in -doMove is exited, which happens once the paused 
flag is set, the -doMove method, the -performOperation method and the 
-calculateNumFiles methods all exit at once. And that means the 
-registerExecutor: can return its result and terminate the auxiliary thread.

I hope that description is clear enough.

Wolfgang






reply via email to

[Prev in Thread] Current Thread [Next in Thread]