Forums Register Login

atomic block of code?

+Pie Number of slices to send: Send
Hi,

I am coding an application. It has a thread that can be requested to stop any time during its execution.
Inside the thread, there are a few lines of code that should be executed all or none. In another word,
if the thread runs in the middle of this block, then outside interrupt/stop request should not stop the thread
before the block finishes. How can this be accomplished? This block of code has nothing to do with database write.

Thanks,
David
+Pie Number of slices to send: Send
Depends on how the "request to stop" is being made. If you're using the deprecated stop() method, then I don't believe there's anything you can do. If you're using interrupt() or a "stop flag" of your own devising, then you simply need to not check these things during the block of statements.
+Pie Number of slices to send: Send
Ernest,

Thanks for your advice. I will try.

David
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2158 times.
Similar Threads
synchronized(this)
Finally block
Using interrupt() to stop a thread
directly stopping a thread
true false question for Thread
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:37:53.