Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
'Coro' segfaults on DO and EVAL
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rachwal Waldemar-AWR001  
View profile  
 More options Feb 22 2005, 12:43 pm
Newsgroups: perl.loop
From: Waldemar.Rach...@motorola.com (Rachwal Waldemar-AWR001)
Date: Tue, 22 Feb 2005 18:43:08 +0100
Local: Tues, Feb 22 2005 12:43 pm
Subject: 'Coro' segfaults on DO and EVAL
[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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rachwal Waldemar-AWR001  
View profile  
 More options Feb 22 2005, 12:32 pm
Newsgroups: perl.loop
From: Waldemar.Rach...@motorola.com (Rachwal Waldemar-AWR001)
Date: Tue, 22 Feb 2005 18:32:29 +0100
Local: Tues, Feb 22 2005 12:32 pm
Subject: 'Coro' segfaults on DO and EVAL

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.

  coro-1.pl
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc Lehmann  
View profile  
 More options Feb 22 2005, 2:44 pm
Newsgroups: perl.loop
From: p...@goof.com (Marc) (Lehmann)
Date: Tue, 22 Feb 2005 20:44:06 +0100
Local: Tues, Feb 22 2005 2:44 pm
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:
> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marc Lehmann  
View profile  
 More options Feb 22 2005, 2:55 pm
Newsgroups: perl.loop
From: p...@goof.com (Marc) (Lehmann)
Date: Tue, 22 Feb 2005 20:55:00 +0100
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rachwal Waldemar-AWR001  
View profile  
 More options Feb 23 2005, 8:55 am
Newsgroups: perl.loop
From: Waldemar.Rach...@motorola.com (Rachwal Waldemar-AWR001)
Date: Wed, 23 Feb 2005 14:55:54 +0100
Local: Wed, Feb 23 2005 8:55 am
Subject: RE: 'Coro' segfaults on DO and EVAL
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »