Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Delayed Events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Delayed Events




Philippe Wicker wrote:

What I suspect is happening is the thread is not being released quickly enough after receiving the event. It is more noticable if I move the mouse about on the desktop. I am playing a MIDI note every 500ms and I can hear the time not being correct.


Can you tell us some more about the threads that are involved: who is the signaling thread?

In the case I am citing here, there is no actual signalling thread. The event times out after the period. At this point, my scheduled object is checked on the top of a priority Q (it is the only object on it in this simple instance), and the time is compared with the time the object was put on the queue. The function for obtaining the time is as follows


DWORD Scheduler::getTime ()
{
  struct timeval current_time;
  DWORD ret = 0;
   if (gettimeofday(&current_time, NULL))
   {
         printf("Unable to get current time");
    }
   else
   {
         ret = (current_time.tv_sec - initial_time.tv_sec) * 1000;
         ret += current_time.tv_usec / 1000;
   }
   return ret;
 }



How (when) do you decide to signal the waiter? Are there several synchronization points in the waiter thread?

There are two mutexes involved, however, there are no other tasks unblocked that are taking them (i.e. MIDI In task). There is a mutext to control adding and removing from the priority Q, however, I know that there is not a sequence problem here. I have seen the problem in another part of the program using events.


What thread is sending the midi note?

This thread. I can also see on the display that there is a delay by printing numbers to the console



This only started occuring after upgrading to Panther from Jaguar. I am after a 5ms resolution. Can Panther offer me this reliably using POSIX threads?


The OS X scheduler can give very sharp resolution using cond_timedwait, a 5ms resolution (and even much better) is possible.

I was preferring 1ms, but I could live with 5ms.

Now the point is how is the midi note sender thread scheduled: is it a time shared or a real time thread? If time shared, did you give it the default priority or did you try to boost its priority?

I tried to boost the priority struct sched_param sp; memset(&sp, 0, sizeof(struct sched_param)); sp.sched_priority=8; if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp) == -1) { printf("Failed to change priority.\n"); }



What is the amount of work it has to execute when it wakes up?

It does not do a lot - In this case it sends the note and adds another scheduled event to the queue. It then waits 500ms


Thanks for taking the time. I was wondering whether I should use something instead of the pThreads API. I was, however, hoping to port to Linux later.

--
Angelo Fraietta

PO Box 859
Hamilton NSW 2303

Home Page


http://www.users.bigpond.com/angelo_f/

There are those who seek knowledge for the sake of knowledge - that is CURIOSITY
There are those who seek knowledge to be known by others - that is VANITY
There are those who seek knowledge in order to serve - that is LOVE
   Bernard of Clairvaux (1090 - 1153)



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mt-smp mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Delayed Events (From: Angelo Fraietta <email@hidden>)
 >Re: Delayed Events (From: Philippe Wicker <email@hidden>)
 >Re: Delayed Events (From: Philippe Wicker <email@hidden>)
 >Re: Delayed Events (From: Angelo Fraietta <email@hidden>)
 >Re: Delayed Events (From: Philippe Wicker <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.