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 Subject: Re: XtAddInput analog in NeXT Step Keywords: X windows, NeXT Step, programming Message-ID: <17517@milton.u.washington.edu> Date: 2 Mar 91 06:51:21 GMT References: <1991Mar1.174526.17075@wdl1.wdl.loral.com> Organization: University of Washington, Seattle Lines: 31 In article <1991Mar1.174526.17075@wdl1.wdl.loral.com> mdm@wdl50.wdl.loral.com (Mike D Marchionna) writes: >In X there is a function called XtAddInput that allows the caller to specify a >UNIX file descriptor to monitor. XtAddInput will invoke a specified callback >routine whenever there is data to read on the indicated file descriptor. You want DPSAddFD() (and the corresponding DPSRemoveFD()). These do just about exactly what you're looking for: when the specified file descriptor becomes readable, the application object (waiting for an event) will call a user-specified function to handle the event. There's another pair of functions for Mach ports: DPSAddPort() and DPSRemovePort(). > .... One approach I had in mind was to start a Mach thread >that performed a blocking read and then sent an Objective C message to NXApp >or some such object that read and processed the data and then restarted the >the thread for the next read. One problem with this: threads and higher level things (such as objc, appkit calls, stdio, malloc, etc.) don't tend to mix very well. The problem is that most libraries are written under the assumption that they are running as the only thread in their address space, so they don't try to lock information before using it. Even just sending one objC message can try to update the objC message cache and if two threads do it at once, things can become screwed up. I usually have subsidiary threads be very stripped-down, simple things, communicating with the main thread via Mach messages or mutex-protected shared memory. -- 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."