ftp.nice.ch/peanuts/GeneralData/Usenet/news/1989/CSN-89.tar.gz#/comp-sys-next/1989/Jan-Apr/How-do-you-use-threads-from-an-objective-c-program?

This is How-do-you-use-threads-from-an-objective-c-program? in view mode; [Up]


Date: Sun 03-Apr-1989 15:56:52 From: Unknown Subject: How do you use threads from an objective-c program? As a recent owner of a NeXT machine and having just received my copy of the technical doc, I wanted to write a simple program to use the interface builder and display postscript to do some graphics on the beast. I rewrote a simple program I've played with since I first learned to program. It uses vector addition to draw a "spirograph." Despite having to learn objective-c and fighting with the idiosyncracies of the interface builder, I got it working in a couple of days. Unfortunately, it has one problem. Once the "draw" method of the spirograph has been invoked, the application is busy until the entire spirograph is drawn. In particular, my "stop" key waits until much too late to do anything. Ahah! I thought. This sounds like a job for threads. So I hacked up the code so that the main drawing loop is a separate function and ran it in another thread. Imagine my surprise when the window server complained that the client connection had closed prematurely and then bombed out. It's repeatable. It draws a spirograph apparently up until the postscript commands get flushed, and then bombs out the window server. Is it something I said? Or am I just doing something incorrectly? This seems like the sort of thing an application might want to do alot of: updating a window while allowing changes to the application's parameters. Can someone tell me what I did wrong or what the right way is to do this? Just point me in the right direction.... Thanks.
Date: Sun 07-Apr-1989 15:41:36 From: Unknown Subject: Re: How do you use threads from an objective-c program? In article <387@hydra.gatech.EDU> roy@prism.gatech.EDU (Roy Mongiovi) writes: >Ahah! I thought. This sounds like a job for threads. So I hacked >up the code so that the main drawing loop is a separate function >and ran it in another thread. Imagine my surprise when the window >server complained that the client connection had closed prematurely >and then bombed out. Yes, it is a job for threads, but no, you cannot do what you tried to do. Reason? The window server currently cannot talk to two seperate threads at the same time within one context. One solution is to have the thread do the compute-intensive stuff and have the main thread do all the PostScript communication. Another solution might be to create another context; but I haven't had the chance to explore that yet and am not sure about the details right now... In the meantime, if you wish to do tons of drawing but you also want to be able to use your menus, buttons, etc at the same time, look at timed entries. With a timed entry, a function can be called repeatedly every so often. Because the timed entries act like events, user events also fire and can be serviced between calls to the timed entry function. Ali Ozer, NeXT Developer Support >From: phd_ivo@gsbacd.uchicago.edu

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.