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

exit freezes the first value it sees #4097

Closed
gfldex opened this issue Jul 19, 2022 · 4 comments
Closed

exit freezes the first value it sees #4097

gfldex opened this issue Jul 19, 2022 · 4 comments
Labels
docs Documentation issue (primary issue type)

Comments

@gfldex
Copy link
Contributor

gfldex commented Jul 19, 2022

Consider the following code:

   END { exit 0 }
    my atomicint $i;
    my @proms;
    for ^20 {
        @proms.push: start { exit ++⚛$i; }
    }

    await @proms;

   END { exit 1 }

Can you guess the exit code? Right now the thread that first gets to set a state container in exit wins. In the case of the END-phasers, the last registered phaser wins. If threads are involved, that may become random as well. Also, any module may add END-phasers at runtime (EVAL being evil). All this is not covered by Roast and we should warn that depending on exit is depeding on impelentation details, which may change whenever the compiler is upgrated.

@gfldex gfldex added the docs Documentation issue (primary issue type) label Jul 19, 2022
@lizmat
Copy link
Collaborator

lizmat commented Jul 19, 2022

FWIW, it feels like a case of DIHWIDT, as you would not typically use exit in an END block, now would you? It feels like a code smell to me.

The alternative was to completely disallow exit from END blocks.

@dontlaugh
Copy link

"DIHWIDT" means, "Doctor, it hurts when I do this", right? 😆

@coke coke added this to the 2023-Quarter 1 milestone Mar 2, 2023
@cfa
Copy link
Contributor

cfa commented Mar 3, 2023

Is this an issue with exit or with threading and phaser order?

It seems like the latter might be worth documenting but I'm unsure how this relates to exit.

@lizmat
Copy link
Collaborator

lizmat commented Mar 3, 2023

No. It was done with the conscious decision that the first time exit is called, it fixates the exit value.

END blocks are guaranteed to always work on a normal exit, any other phasers might not as exit bypasses the whole call chain.

Note that this is different from throwing an exception: that won't actually exit until all applicable phasers have run.

@lizmat lizmat changed the title exit is not reliable exit freezes the first value it sees Mar 3, 2023
lizmat added a commit that referenced this issue Mar 4, 2023
@lizmat lizmat closed this as completed Mar 4, 2023
coke pushed a commit that referenced this issue May 9, 2023
coke pushed a commit that referenced this issue Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

5 participants