Re: Sound Manager & MIDI callbacks, interrupts and threads
Re: Sound Manager & MIDI callbacks, interrupts and threads
- Subject: Re: Sound Manager & MIDI callbacks, interrupts and threads
- From: Bill Stewart <email@hidden>
- Date: Mon, 18 Feb 2002 15:56:08 -0800
on 18/2/02 6:47 AM, Andy Robinson wrote:
>
Thanks again for more replies.
>
>
What I now plan to do is this. I'm going to ignore the instruction not
>
to put a lock in a callback since some people tell me that in fact a
>
lock is ok, and no-one has proposed any other way of protecting critical
>
sections. If anyone is going to tell me again not to do this, then
>
please tell me what I _should_ do instead. In fact, is the instruction
>
not to put a lock in a callback a hangover from Classic Mac when the
>
callback would be running in "interrupt time" rather than a true thread
>
of its own?
Lets examine a scenario.
You have a lock you acquire in the I/O thread that you share with the event
thread.
Lets say that the event thread cannot run because it is waiting on something
else to happen (and there can be MANY instances of this), but you have also
got the lock in the event thread for the I/O thread...
A lock is OK if you know exactly what both of your threads are doing that
are involved in the lock.
There are other strategies that you can employ to avoid locking...
The problem with having the I/O thread depend on a lock is that it runs at a
very high priority and if it is blocked your entire machine will become
catatonic unitl the I/O thread gets nuked and then lets the other thread
run.
>
I've downloaded the excellent pthread reference that someone gave a
>
pointer to:
>
http://www.tru64unix.compaq.com/docs/base_doc/DOCUMENTATION/
>
V51A_PDF/ARH9RBTE.PDF
>
>
And then I wrap pthread_mutex_lock/unlock around the critical bits of
>
queue manipulation in both the main app code and the callback. Seems to
>
work ok, I'll think again if it crashes.
Personally I think it is a bad idea to have the I/O thread and the main
thread locking because the main thread (dealing with events and UI) can be
blocked for any number of reasons that are totally opaque to you. But you'll
know soon enough when that causes problems if you find them before you ship
Bill
>
>
Easy when you know how. Thanks again.
>
>
Andy Robinson, Seventh String Software, www.seventhstring.demon.co.uk
>
_______________________________________________
>
coreaudio-api mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
>
Do not post admin requests to the list. They will be ignored.
mailto:email@hidden
tel: +1 408 974 4056
__________________________________________________________________________
"Thousands of years ago, cats were worshipped as gods. We have never
forgotten this."
__________________________________________________________________________
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.