Path: utzoo!utgpu!water!watmath!clyde!bellcore!decvax!ucbvax!hplabs!well!ewhac From: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Newsgroups: comp.sys.amiga.tech Subject: Re: Killing a task using SetExcept() Keywords: tasking, signals, exception processing Message-ID: <5395@well.UUCP> Date: 8 Mar 88 22:36:09 GMT References: <7409@agate.BERKELEY.EDU> <1401@louie.udel.EDU> <1406@louie.udel.EDU> Reply-To: ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) Organization: Half-Mars Mechanical Attachment Lines: 46 [ Personally, I'd like to see it called comp.sys.amiga.wizards.... ] In article <1406@louie.udel.EDU> schifala@udel.EDU (Jim Schifalacqua) writes: >Hello, > I am trying to design a neat way to kill tasks spawned by my programs. >I want to use exception processing via SetExcept and the tc_ExceptCode field. >What I mean to do is point tc_ExceptCode at my cleanup routine and use >SetExcept to point a signal that will start thisup from within my task. >My question is how will the system react to a RemTask() call from within the >exception? The more I think about this the more it seems to me that I am >going to crash the system- what is the true wisdom on this? > The True Wisdom is: Don't do it. I tried pulling this trick in a program I wrote. Academically, it is, indeed, possible to asynchronously pop out of a program using an exception, and then longjmp() out of it if you want. However, from a practical standpoint, this is riddled with problems. Among these is freeing up resources that you may have (invisibly) allocated. Suppose you draw a line. The sequence for making any use of the blitter is: OwnBlitter (); WaitBlit (); StompBlitterRegisters (); StartBlitter (); DisownBlitter (); The Own/DisownBlitter() calls are invisible to you, but they still exist. If you take an exception while stomping the blitter registers (you own the blitter), and then asynchronously exit from the program, you will still own the blitter. Since you no longer exists, the blitter is owned by no one, and no one can free it. So the system stops. This problem applies to semaphores in general. Unless you are *ABSOLUTELY CERTAIN OF WHAT YOU ARE DOING*, don't use exceptions except in a "subroutine" capacity. They are quite handy, though, once you know what to avoid... _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ Leo L. Schwab -- The Guy in The Cape ihnp4!ptsfa -\ \_ -_ Recumbent Bikes: dual ---> !{well,unicom}!ewhac O----^o The Only Way To Fly. hplabs / (pronounced "AE-wack") "Work FOR? I don't work FOR anybody! I'm just having fun." -- The Doctor