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

@only_one doesn't reset within function #102

Closed
carstenbauer opened this issue Mar 28, 2024 · 1 comment
Closed

@only_one doesn't reset within function #102

carstenbauer opened this issue Mar 28, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@carstenbauer
Copy link
Member

Works:

julia> using OhMyThreads

julia> @tasks for i in 1:8
           @set ntasks = 2
       
           println(i, ": before")
           @only_one begin
               println(i, ": after")
           end
       end
5: before
1: before
5: after
2: before
3: before
6: before
6: after
7: before
7: after
8: before
4: before
8: after

julia> @tasks for i in 1:8
           @set ntasks = 2
       
           println(i, ": before")
           @only_one begin
               println(i, ": after")
           end
       end
1: before
5: before
1: after
6: before
2: before
7: before
8: before
2: after
3: before
3: after
4: before
4: after

Doesn't work:

julia> function f()
           @tasks for i in 1:8
               @set ntasks = 2
       
               println(i, ": before")
               @only_one begin
                   println(i, ": after")
               end
           end
       end
f (generic function with 1 method)

julia> f()
1: before
1: after
2: before
5: before
2: after
3: before
3: after
4: before
4: after
6: before
7: before
8: before

julia> f()
1: before
5: before
6: before
7: before
2: before
3: before
4: before
8: before
@carstenbauer carstenbauer added the bug Something isn't working label Mar 28, 2024
@carstenbauer carstenbauer changed the title @only_once doesn't reset within function @only_one doesn't reset within function Mar 28, 2024
@carstenbauer carstenbauer mentioned this issue Mar 28, 2024
@carstenbauer
Copy link
Member Author

carstenbauer commented Mar 28, 2024

Functional analog is working fine:

julia> using OhMyThreads

julia> using OhMyThreads.Tools: OnlyOneRegion, try_enter!

julia> function g()
           r = OnlyOneRegion()
           tforeach(1:8; ntasks=2) do _
               println("A")
               try_enter!(r) do
                   println("B")
               end
           end
       end
g (generic function with 1 method)

julia> g()
A
A
B
A
B
A
A
A
A
B
A
B

julia> g()
A
A
B
A
A
B
A
B
A
A
B
A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant