prioritizing threads
prioritizing threads
- Subject: prioritizing threads
- From: Seth Delackner <email@hidden>
- Date: Tue, 28 Dec 2004 16:20:39 +0000
- Mail-followup-to: email@hidden
In trying to debug this, I wrote a small test app that launches some threads and tries to force each of them to run a different percentage of the time. Nothing I've tried seems to work.
Looking at Sampler.app, each thread always gets to run the same percent of the time, which is not what I want. One thread is the main worker, and the others are much less important and could nearly starve for all I care.
I've tried, as per previous stuff on this list:
making the lesser threads lock an NSLock while the main thread is doing heavy work
using the thread_policy_set function (see (1) below) with either 1 for the lesser and 5 for the main or just 6 for the main and not calling it for the lessers.
and finally the simple [NSThread setThreadPriority:] with 0.1 for lessers and 0.9 for the main thread.
Each thread in my minimal test app is just being created by NSThread detachNewThreadSelector, then:
workTimer = [[NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(work:) userInfo:nil repeats:YES] retain];
rl = [NSRunLoop currentRunLoop];
[rl addTimer:workTimer forMode:NSDefaultRunLoopMode];
[rl run];
And work: just logs some output;
(1) the code to use thread_policy_set:
kern_return_t error;
thread_extended_policy_data_t extendedPolicy;
thread_precedence_policy_data_t precedencePolicy;
extendedPolicy.timeshare = 0;
error = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT);
if (error != KERN_SUCCESS) {
#if DEBUG
mach_error("Couldn't set feeder thread's extended policy", error);
#endif
}
precedencePolicy.importance = priority;
error = thread_policy_set(mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT);
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden