Xref: utzoo comp.sys.next:14706 comp.os.mach:869 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!ogicse!milton!wiml From: wiml@milton.u.washington.edu (William Lewis) Newsgroups: comp.sys.next,comp.os.mach Subject: Re: NXPing() in a thread Message-ID: <19044@milton.u.washington.edu> Date: 26 Mar 91 03:35:31 GMT References: <00946246.F502A0C0@uno.edu> Organization: University of Washington, Seattle Lines: 39 I've changed the Newsgroups: line, as the query isn't really relevant to Objective-C ... In article <00946246.F502A0C0@uno.edu> jrscs@uno.edu writes: > I have a question on the use of NXPing() in a detached thread. The >detached thread processes some sound data while the "main" thread handles >the user interface. NXPing() works fine inside the main thread but it >hangs my NeXT if it call it inside the method for which the thread was >launched. I can't imagine how it would hang the whole NeXT, but I can see how it could hang your application without much trouble. The trouble stems from the fact that the DPS routines (in fact, almost all library routines that change any sort of global state, including seemingly safe ones as close()/open()) are not reentrant; they're not designed for a multi-threaded environment. So when you call NXPing() in a subsidiary thread, the main thread is probably sitting in DPSGetEvent() (assuming it's a normal Appkit-using application), and both threads attempt to interact with the window server simultaneously, with undesirable results. > ( The NXPing() inside the detached thread ( supposedly ) >coordinates the highlighting of a word in a window with the pronunciation >of that word. ) It would be really nice if the DPS*() routines _were_ reentrant (or at least used mutexes or something... hello NeXT?) As far as I know, the only way to do this is to send a Mach message to a port registered via DPSAddPort(), which will wake up the main thread; the handler on that port can then NXPing() or do other arbitrary processing. Unfortunately this seems like a whole lot more trouble than it should be ... -- wiml@milton.acs.washington.edu Seattle, Washington (William Lewis) | 47 41' 15" N 122 42' 58" W "Just remember, wherever you go ... you're stuck there."