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

Support early termination (e.g. break) #96

Open
carstenbauer opened this issue Mar 21, 2024 · 2 comments
Open

Support early termination (e.g. break) #96

carstenbauer opened this issue Mar 21, 2024 · 2 comments

Comments

@carstenbauer
Copy link
Member

E.g. break within @tasks as mentioned in #95 (comment)

@carstenbauer carstenbauer changed the title Support early termination Support early termination (e.g. break) Mar 21, 2024
@adienes
Copy link

adienes commented Apr 1, 2024

maybe break should be required to be guarded behind @one_by_one (or just @break )

@disberd
Copy link

disberd commented May 2, 2024

I started using OhMyThreads and I have to say I like it a lot so far, but indeed I use this for speeding up long running simulations and I'd like to be able to interrupt the execution (while also interrupting the execution of the various tasks spawned by @tasks to avoid hogging CPU for an interrupted simulation till the end of the original @tasks iteration).

At the moment i resort to throwing an error within the body of @tasks for stopping early like so:

mutable struct AbortController
    @atomic stop::Bool
end
AbortController() = AbortController(false)

controller = AbortController()
try
	@tasks for i in 1:100
		if @atomic(controller.stop)
			error("Aborted")
		end
		sleep(2) # expensive computation
		@info i
	end
finally
	@atomic controller.stop = true
end

which seems to correctly kill the spawned tasks.

Is there a better way to achieve this?

@carstenbauer, @MasonProtter

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

3 participants