help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to exit out of a function ? what is try-catch-throw in terms of


From: Alf P. Steinbach
Subject: Re: How to exit out of a function ? what is try-catch-throw in terms of Program Counter
Date: Mon, 03 Dec 2007 00:51:52 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051201 Thunderbird/1.5 Mnenhy/0.7.3.0

* David Thompson:
On Mon, 05 Nov 2007 06:07:25 +0100, "Alf P. Steinbach"
<alfps@start.no> wrote:

* David Thompson:
On Sun, 21 Oct 2007 00:55:53 +0200, "Alf P. Steinbach"
<alfps@start.no> wrote:

The closest equivalent in C would be a 'longjmp'. However, a C++ exception is more limited, in that it will only jump up the call chain,
C longjmp/setjmp also is only guaranteed to work up the stack; the
fact that _some_ implementations can work cross-stack and in
particular cross-thread is not standard nor portable.
So?

But also, what on Earth do you mean by a cross-thread longjmp? I implemented coroutines in terms of longjmp at the time that was popular, so the concepts involved are not unfamiliar to me. Yet I fail to envision what you could be talking about, especially as "fact". I think

IME 'coroutine' has been used for several slightly different concepts,
but if you mean the one of separate threads of control passing CPU
ownership often along with data anytime they choose, also known more
specifically as cooperative/nonpreemptive threading/tasking, yes. I
think you are agreeing that it did actually work, because 'restoring'
PC and SP (or equivalents) was enough; but I am pointing out it wasn't
and isn't _required_ to work that way.

perhaps you're talking about restoring the full context (registers etc) of a moment in a thread's execution?

IME a cooperative switch itself doesn't need to save and restore other
state, as the language mechanism(s) e.g. 'call yield' handle it. Or
for cache-y things it happens automatically, or mostly automatically.

Sorry, I fail to see the point, whatever it is.

But regarding definition of 'coroutine', it really doesn't map to more than one concept.

Coroutines are treated in Knuth's TAOCPM, which locked in the terminology (although Knuth didn't always succeed in in establishing convention, e.g. he had to redraw his trees because he at first did them with the root down, while the rest of the CS community chose root up, and same for his misconception of "real time" as "reel time", he couldn't make that stick either :-) ); some languages, notably Modula-2, had built-in support for coroutines; you can find some dicussion of coroutines at <url: http://en.wikipedia.org/wiki/Coroutine>.

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]