'Coro' module by Lehmann looks so attractive that I started thinking about re-design event loop approach of our simulator to utilize coroutines. It would give completely new capability--users could write pure perl scripts controlling our simulator having access to its internals. I looked at 'ithreads' earlier, but this model was completely useless as our application is heavy with "state data".
However, the first trial script with Coro segfaults unexpectedly when I do perl's 'do "SCRIPT"'. 'eval "CONTENTS"' also crashes in the same way. A sample script reproducing the error is below. Note, that when I commented out the lines: eval q| --and-- |; everything worked OK. Below the script there are outputs from two runs: first with EVAL, second without it.
I tried it with perl 5.8.4 compiled without ithreads on Solaris, and with current distribution of perl 5.8.6-4 with ithreads on Cygwin, and got exactly the same results, so big chances are the problem is fully reproducible with the perl on your machine. In both cases it was latest ver 1.0 of Coro.
START Start 3 value 3 -> 3 Start 5 value 5 -> 5 Start 7 value 7 -> 7 value 3 -> 2 value 5 -> 4 value 7 -> 6 value 3 -> 1 value 5 -> 3 value 7 -> 5 value 5 -> 2 value 7 -> 4 value 5 -> 1 value 7 -> 3 Segmentation fault <----- :( :(
### Output with EVAL commented out (ok)
START Start 3 value 3 -> 3 Start 5 value 5 -> 5 Start 7 value 7 -> 7 value 3 -> 2 value 5 -> 4 value 7 -> 6 value 3 -> 1 value 5 -> 3 value 7 -> 5 value 5 -> 2 value 7 -> 4 value 5 -> 1 value 7 -> 3 value 7 -> 2 value 7 -> 1 DONE.
'Coro' module by Lehmann looks so attractive that I started thinking about re-design event loop approach of our simulator to utilize coroutines. It would give completely new capability--users could write pure perl scripts controlling our simulator having access to its internals. I looked at 'ithreads' earlier, but this model was completely useless as our application is heavy with "state data".
However, the first trial script with Coro segfaults unexpectedly when I do perl's 'do "SCRIPT"'. 'eval "CONTENTS"' also crashes in the same way. A sample script reproducing the error is below. Note, that when I commented out the lines: eval q| --and-- |; everything worked OK. Below the script there are outputs from two runs: first with EVAL, second without it.
I tried it with perl 5.8.4 compiled without ithreads on Solaris, and with current distribution of perl 5.8.6-4 with ithreads on Cygwin, and got exactly the same results, so big chances are the problem is fully reproducible with the perl on your machine. In both cases it was latest ver 1.0 of Coro.
START Start 3 value 3 -> 3 Start 5 value 5 -> 5 Start 7 value 7 -> 7 value 3 -> 2 value 5 -> 4 value 7 -> 6 value 3 -> 1 value 5 -> 3 value 7 -> 5 value 5 -> 2 value 7 -> 4 value 5 -> 1 value 7 -> 3 Segmentation fault <----- :( :(
### Output with EVAL commented out (ok)
START Start 3 value 3 -> 3 Start 5 value 5 -> 5 Start 7 value 7 -> 7 value 3 -> 2 value 5 -> 4 value 7 -> 6 value 3 -> 1 value 5 -> 3 value 7 -> 5 value 5 -> 2 value 7 -> 4 value 5 -> 1 value 7 -> 3 value 7 -> 2 value 7 -> 1 DONE.
On Tue, Feb 22, 2005 at 06:32:29PM +0100, Rachwal Waldemar-AWR001 <Waldemar.Rach...@motorola.com> wrote: > However, the first trial script with Coro segfaults unexpectedly when I do > perl's 'do "SCRIPT"'.
The problem is that Coro cannot reliably work when you jump in/out of currently-being-compiled code, as perl changes too much of global state when compiling programs, and doesn't tolerate context switches at that point.
You should be able to compile code, and use cede in it, but it has to be done in seperate steps.
(i.e. eval { } instead of eval "").
The workaround for 'do ""' would be to read the string, compile it into a sub, and run it.
It might be possible to support just that case, as compiling is almost finished, and it might be possible to detetc this case and barf with a better error message. I will have a look at it.
> Do I do something wrong?
Not really, you are just running into a limitation that perl sets, and is not documented anyhwere :/
On a less serious level, yes, you do sth. wrong:
> eval q| > |;
Of course, recompiling the code makes no sense, but I guess it's just for the sake of the example. You _should_ be able to replace all occurrences of that by seperate 'my $sub = eval "sub { ... }"; &$sub' invocations.
-- The choice of a -----==- _GNU_ ----==-- _ generation Marc Lehmann ---==---(_)__ __ ____ __ p...@goof.com --==---/ / _ \/ // /\ \/ / http://schmorp.de/ -=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE
On Tue, Feb 22, 2005 at 06:32:29PM +0100, Rachwal Waldemar-AWR001 <Waldemar.Rach...@motorola.com> wrote: > perl's 'do "SCRIPT"'. > 'eval "CONTENTS"' also crashes in the same way. A sample script reproducing
I made an effort of supporting some cases of cede'ing while compiling, the result is in Coro-1.1 (soon on CPAN, or at http://data.plan9.de/Coro-1.1.tar.gz). It also has better amd64-linux support.
Maybe that helps your case, but if there is a problem, try to avoid eval "..." and use eval "sub {...}".
-- The choice of a -----==- _GNU_ ----==-- _ generation Marc Lehmann ---==---(_)__ __ ____ __ p...@goof.com --==---/ / _ \/ // /\ \/ / http://schmorp.de/ -=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE
Marc, Applied your advice with enclosing 'sub' to delay execution, and now the stuff works great! I examined plain 'do/eval' with your new Coro 1.1, and... this also works, at least on my little example. I will be extending the prototype by I/O and synch primitives from Coro set, then. Thank you very much, Waldemar.
-----Original Message----- From: p...@goof.com [mailto:p...@goof.com] Sent: Tuesday, February 22, 2005 8:55 PM To: Rachwal Waldemar-AWR001
Cc: perl-l...@perl.org Subject: Re: 'Coro' segfaults on DO and EVAL
On Tue, Feb 22, 2005 at 06:32:29PM +0100, Rachwal Waldemar-AWR001 <Waldemar.Rach...@motorola.com> wrote: > perl's 'do "SCRIPT"'. > 'eval "CONTENTS"' also crashes in the same way. A sample script > reproducing
I made an effort of supporting some cases of cede'ing while compiling, the result is in Coro-1.1 (soon on CPAN, or at http://data.plan9.de/Coro-1.1.tar.gz). It also has better amd64-linux support.
Maybe that helps your case, but if there is a problem, try to avoid eval "..." and use eval "sub {...}".
-- The choice of a -----==- _GNU_ ----==-- _ generation Marc Lehmann ---==---(_)__ __ ____ __ p...@goof.com --==---/ / _ \/ // /\ \/ / http://schmorp.de/ -=====/_/_//_/\_,_/ /_/\_\ XX11-RIPE