Article View: comp.sys.next.programmer
Article #125usleep and sound, signals and threads
From: Sam Streeper
Date: Tue, 03 Nov 1992 22:20
Date: Tue, 03 Nov 1992 22:20
29 lines
1342 bytes
1342 bytes
Someone was just trying to add sound to a BackSpace module and ran into a sneaky problem that has been discussed before but bears repeating. usleep() is implemented via signals (a questionable strategy IMHO), and many of the soundkit functions surreptitiously use threads to keep the sound buffers full. Signals and threads do not mix gracefully, and the sound thread may catch the signal that was supposed to wake up the usleep() function, hanging it forever. The solution is to pick some waiting method that doesn't use signals; for example waiting on a mach port. One easy way to do this is to wait for an event that will never be received with an appropriate timeout. For example: NXEvent dummyEvent; [NXApp peekNextEvent:0 into:&dummyEvent waitFor:timeout threshold: NX_MODALRESPTHRESHOLD]; Maybe this will keep someone from tearing one's hair out. -sam -- Opinions expressed herein are not those of my employer. They're not even mine. There is water at the bottom of the ocean. Hi Mom!
Technical Details
Message-ID:
<5724@rosie.NeXT.COM>Path:
arc1-ca.pugleaf.net!sparky!uunet!rosie!NeXT.comShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!rosie!NeXT.com From: sam_s@NeXT.com (Sam Streeper) Newsgroups: comp.sys.next.programmer Subject: usleep and sound, signals and threads Message-ID: <5724@rosie.NeXT.COM> Date: 3 Nov 92 22:20:39 GMT Sender: news@NeXT.COM Reply-To: sam_s@NeXT.com Lines: 29