Re: -forceCancel an NSOperation
Re: -forceCancel an NSOperation
- Subject: Re: -forceCancel an NSOperation
- From: Wim Lewis <email@hidden>
- Date: Wed, 01 Mar 2017 14:44:52 -0800
On Mar 1, 2017, at 2:23 PM, Carl Hoefs <email@hidden> wrote:
> Normally, that is sufficient. But under some circumstances, it's possible for an executing NSOperation to get hung up doing I/O or for some other reason. No means is given to forcibly stop the execution of an NSOperation, and there's no -thread method to obtain its thread and terminate it.
As Ken Thomases says, this probably can't be done safely in the *general* case.
If you have a specific operation which might need to be asynchronously interrupted, you can probably install a per-thread signal handler (remember to clean it up on completion) and stash a thread identifier somewhere on the NSOperation where your other code can find it. The handler could cancel any blocked syscall and/or set a flag somewhere it can be cheaply checked by cpu-intensive code.
Truly asynchronously terminating a thread is unsafe unless you're very careful about what might be happening in there: lots of library calls can take out global locks temporarily (e.g., anything that uses malloc/free or sends objc messages), and dropping one of those locks will promptly cause your application to hang.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden