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