• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: prioritizing threads
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: prioritizing threads


  • Subject: Re: prioritizing threads
  • From: Tim Hewett <email@hidden>
  • Date: Tue, 28 Dec 2004 23:04:43 +0000

Hello,

To actually control proportions of thread CPU usage accurately
you'll be best off using real time threads. This seems to be quite
specialist and not very well documented (so far as I can see)
but you can see a real life example in the source of Apple's
Firewire DV libraries - these use real time threads for importing
and exporting DV video for the likes of iMovie.

Get the current Firewire SDK from developer.apple.com. Look
for a function called setThreadPriority() in a file called DVLib.c.
See if you can understand how it works... then please tell me :-)

Tim.


On 28 Dec 2004, at 19:03, email@hidden wrote:

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
  • Follow-Ups:
    • Re: prioritizing threads
      • From: Seth Delackner <email@hidden>
  • Prev by Date: Re: TableView insanity... please help!!
  • Next by Date: NSApp sendAction: to: from question
  • Previous by thread: prioritizing threads
  • Next by thread: Re: prioritizing threads
  • Index(es):
    • Date
    • Thread