NSThread to NSOperation and blockUntil
NSThread to NSOperation and blockUntil
- Subject: NSThread to NSOperation and blockUntil
- From: Trygve Inda <email@hidden>
- Date: Mon, 21 Mar 2016 18:07:10 -0700
- Thread-topic: NSThread to NSOperation and blockUntil
I have a thread that is invoked with:
[NSThread detachNewThreadSelector:@selector(threadMethod:) toTarget:self
withObject:self];
It uses NSConditionLock and works well.
This thread performs a complex process but does it slowly so as to not use
much processor time. I specify how long I want it to take (1 to 30 minutes)
and use:
// block this task until time has elapsed or an exit signal is received.
if ([[self lock] lockWhenCondition:kConditionThreadMustExit beforeDate:[self
blockUntil]])
[[self lock] unlock];
blockUntil simply checks to see how much work has been done vs how much time
has passed and if 50% of the work has been done, blocks until 50% of the
time has passed. It works well since the work is very linear.
I would like to move this to NSOperation and NSOperationQueue but I see no
way to replicate this behavior. My current thread is limited to a single
processor core and with NSOperation I could split it to multiple cores, but
in so doing I seem to lose this "delay for a while" bit.
Any ideas?
Thanks.
_______________________________________________
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