Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example 15 from "Try Ceu" page isn't correct #135

Open
danbst opened this issue Jan 17, 2019 · 3 comments
Open

Example 15 from "Try Ceu" page isn't correct #135

danbst opened this issue Jan 17, 2019 · 3 comments

Comments

@danbst
Copy link

danbst commented Jan 17, 2019

I've modified code (copying here original one)

var int ret = 0;
par/or do
    await async (ret) do
        // calculates fat of 10
        var int fat = 1;
        var int i = 10;
        loop do
            if i == 0 then
                break;
            end
            fat = fat * i;
            i = i - 1;
        end
        ret = fat;
    end;
with
    await 1s;  // kill the async if it takes long
    ret = 0;
end
escape ret;

and set var int i = 1;. I expected factorial of 1 to be computed faster than 1s, but surprisingly result was 0.

How can this be explained?

@fsantanna
Copy link
Collaborator

Hi @danbst,

The behavior is correct. Unfortunately, the example/explanation is mostly incomplete.
To get the expected behavior, you need to split the emit 1s, into multiple emit 100ms.

Since the examples are running on the server in "simulation mode", all input is artificial and has no relation with the real world.
If your program says emit 1s, Céu will just assume that happened and simulate that 1s elapsed, so it will not have time to advance the async trail.
When you split the simulation into multiple steps of 100ms, each time Céu will also advance the async trail.

(As an alternative, you could also use an async/thread trail to get real parallelism, but it's not supported in the online tutorial.)

Let me know if you have further question.

Regards,
Francisco

@danbst
Copy link
Author

danbst commented Jan 17, 2019

Oh, ok. Then I propose to change that example, so there are 10 emit 1s; in "input", and await 10s in code. So, reducing factorial number would actually work.

@fsantanna
Copy link
Collaborator

Sure! Thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants