Related articles |
---|
setjmp/longjmp implementations hbaker@netcom.com (1994-02-16) |
Re: setjmp/longjmp implementations chase@Think.COM (1994-02-16) |
Re: setjmp/longjmp implementations pardo@cs.washington.edu (1994-02-17) |
Newsgroups: | comp.compilers |
From: | pardo@cs.washington.edu (David Keppel) |
Keywords: | C, optimize |
Organization: | Computer Science & Engineering, U. of Washington, Seattle |
References: | 94-02-097 94-02-104 |
Date: | Thu, 17 Feb 1994 19:43:48 GMT |
>hbaker@netcom.com (Henry G. Baker) writes:
>[Do compilers notice `setjmp' in their programs?
> Are they ever open-coded?]
Compilers are allowed to notice but not required to notice. I believe
there are machines where the only workable implementation requires
compiler help, which smacks, anyway, of open-coding (but ask on
`comp.std.c' to be sure).
>[Does anybody know the speed of their setjmp/longjmp?
> Some implementations were criticized by those doing stack switching.]
I don't know real numbers any more, but the costs do vary widely. Under
VAXen/BSD, each stack frame was popped off as if the function did a
sequence of "normal" returns except that each used the "wrong" return pc.
`longjmp' time was thus proportional to the number of call frames being
`longjmp'-ed over. On other machines, the processor merely loads up some
registers from the jump buffer (jmp_buf).
Using `setjmp' and `longjmp' to do stack switching is guaranteed to be
nonportable. There are some machines where it happens to work.
>[The ANSI Document gives the impression that implementations don't
> need to declare globals as `volatile'.]
Actually, it was K&R2; I'd ask over on `comp.std.c' for details about the
detail rules on `setjmp'.
And now an aside...
Note that a number of systems -- Smalltalk-80, many LISPs, do include
nonlocal returns, stack switches, and (some kind of) concurrency as a part
of the language model. C takes a more minimalist approach that makes it
easy to implement the language (and programs written in the language)
efficiently, but since the language lacks these constructs (and since
people want them) they have since been grafted on top.
ANSI has codified `setjmp' so it is guaranteed to work (at least if the
compiler conforms to the standard), but stack switch and concurrency have
not been standardized, so it is still a problem to write a safe threads
package for C (even using asm to do the context switch) because a compiler
*could* (though it might be unlikely) perform optimizations and transforms
that break assumptions in the threads package.
;-D on ( A sign of the divides ) Pardo
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.