Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.eiffel Subject: Re: Functions without side effects (was Old confusion) Message-ID: <6135@goanna.cs.rmit.oz.au> Date: 6 Jun 91 09:31:34 GMT References: <1991May30.141218.3446@mstr.hgc.edu> <327@alfrat.uucp> <1991Jun5.140023.4614@mstr.hgc.edu> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 36 In article <1991Jun5.140023.4614@mstr.hgc.edu>, jcm@mstr.hgc.edu (James McKim) writes: > In article <1991Jun4.041233.19046@runx.oz.au> chrisv@runx.oz.au (Chris Velevitch) writes: > >Testing the result of 'test_and_set' routine is the same as testing > >'got_resource'. So 'test_and_set' should be a procedure and the result > >available through some other feature, in this case 'got_resource'. > Hallellujah and welcome soul brother! If you two "soul brothers" will have the kindness to label your programs in bright red letters "DANGER -- DO NOT USE" I will much appreciate it. This separation between setting a flag and accessing it is a *disaster* in multi-threaded systems. That includes systems which can handle external interrupts (such as SIGINT). Consider for example C's interface to system calls: if you have an interrupt handler in your program you can *never* be certain that if (open(...) == 1) { /* inspect errno to see what went wrong */ } will work. (The irony is that the _assembly_code_ interface that I occasionally used in UNIX V7 on a PDP-11 *is* safe.) You should *never* allow a separation between return from an operation and delivering the results unless you can be absolutely certain that no other use of that operation will intervene. If you don't like procedures that return a status value, add an extra "status" argument to the interface. But please, in the interests of writing code that stands a chance of working in a multi-threaded environment (like this Encore, or like SunOS 4, or like SVR4) or in an environment with interrupts (like a PC or VMS or ...), *don't* leave "outcomes" lying around in variables where they can be trampled on. -- Should you ever intend to dull the wits of a young man and to incapacitate his brains for any kind of thought whatever, then you cannot do better than give him Hegel to read. -- Schopenhauer.