[once again but without *.pl attachement]

Hello,

'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.

Do I do something wrong?

I'd be appreciated for any help.
Waldemar.

-----------------------------------
#!/usr/bin/perl -w

use strict;

use Coro;
use Coro::Event;

foreach (3, 5, 7) {

    my $pid = new Coro sub {
        my $count = $_[0];
eval q|
        my $value = $count;
        print "Start $value\n";

        while ($value) {
            print "value $count -> $value\n";
            --$value;
            cede;
        }
|;
    }, $_;

    $pid->ready;
}

print "START\n";
loop;
print "DONE.\n";
-----------------------------------

### Output with EVAL (segfault)

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.

Reply via email to