killing threads externally

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

killing threads externally

Post by mk8 »

is it possible to kill a thread from the outside? like, say, i make it sleep for 5 seconds, but 2 seconds into its sleep i decide to kill it. since Thread:kill() was removed, what do i do?
hippity hoppity ur code is my property (thanc in advanc)
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: killing threads externally

Post by Andlac028 »

Maybe try to use thread:release(), but I am not sure, what it will do…

Otherwise use channels to communicate and divide work into smaller pieces, so that it will check if there are some new messages between tasks.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: killing threads externally

Post by zorg »

You send it a message to end itself, and it will... after the 5 second sleep has passed.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: killing threads externally

Post by pgimeno »

I don't think all systems support killing a thread, so I'd go with zorg's suggestion.

For extra responsivity, instead of sleeping for 5 seconds, you can loop 50 times sleeping for 0.1 seconds and checking whether a termination request was issued on each iteration.
Rigachupe
Citizen
Posts: 83
Joined: Fri Jun 18, 2021 11:21 am

Re: killing threads externally

Post by Rigachupe »

By turning off the computer you kill any thread even this forum thread. An odd solution i know. Sorry.
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

Re: killing threads externally

Post by mk8 »

pgimeno wrote: Mon May 22, 2023 11:54 am I don't think all systems support killing a thread, so I'd go with zorg's suggestion.

For extra responsivity, instead of sleeping for 5 seconds, you can loop 50 times sleeping for 0.1 seconds and checking whether a termination request was issued on each iteration.
that was something i considered, but wanted to avoid. what i didn't realize is that it doesn't matter whether the thread terminates during or after the sleep, as it does nothing either way lol
hippity hoppity ur code is my property (thanc in advanc)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 47 guests