I have a quick question. I noticed that each time tensorflow.train.SummaryWriter is called, a new thread is created. Calling close() method of summarywriter will not kill the thread.
I am wondering if there is a way to kill the threads created by summarywriters?
Thank you for your help!
Best
Related
I want to suspend a thread in a process and also I want to get all of the threads.
But I googled and didn't find a method to list or change it.
Example, what I mean:
dwm.exe has these threads inside: http://prntscr.com/hru52n (Opened with process explorer).
But I want to make it on cmd (.bat). I really do not know what I should do.
I would be happy if someone helps me.
Thank you!
I want to suspend a thread in a process
Why? It is not advised to do this as there is a good chance you will deadlock the process:
Q: What is the result of suspending a thread in the middle of a
threadsafe operation?
[The] Critical section never gets unlocked if you’re inside it.
Q: What happens if – subsequently – you try to access that same object
(in this case, the console) from another thread?
Deadlock…
Source Why you should never suspend a thread
I created a thread from main and detach it from main thread.
I want to kill this thread when it is in progress state.
I tried std::terminate() But it kill whole process . This thing i didn't want.
I want to kill that progress thread and start another thread in C++.
Please help me to solve this for std::thread.
I was studying about multi-threading and came across join().
As I understand right, using join() on the thread makes process wait until 'joined' thread terminates. For example, calling t1.join() in main will make main wait until the job in thread t1 is finished and t1 terminates.
I'm just curious that how the function join() make this possible - how does it make current thread 'blocked' inside the function? Does join() force execution of joined thread first so any other thread should wait until that thread terminates? Or, is there some way to communicate between two threads(the thread who called join() and the thread who is joined)?
I will be waiting for the answer. Thanks a lot!
To be able to join you need to be able to wait on some event. Then join looks like this:
function join(t : Thread)
// do this atomically
if already done
return
wait on termination event of t
end
Waiting can be done in one of two ways:
Looping and periodically checking if the event has happened (busy wait)
Letting the system reclaim the resources of the thread and be woken up on a system event, in that case waking the thread is managed by the scheduler of the OS
It's rather language specific.
Once you create a thread, it starts running.
A join operation is when your main process stops and waits for the thread to exit and capture a return code. It will block until your thread completes - that's rather the point, as it allows for a synchronization to occur - everything in your program is at a 'known state'.
Related is the detach operation, which is effectively saying 'I don't care any more'.
I have a QThread that fetches data from the web. Sometimes the user asks for something else, and the data needs to be fetched changes as well.
In my current configuration, I call terminate() upon the thread, change the input data, and call start() on the thread again. Now, that works fine, but sometimes I get the main eventloop stuck when calling isRunning() or isFinished() upon a terminated thread. It gets stuck forever, and does not recover until I kill the process.
Why would isRunning() or isFinished() hung in the first place? They don't suppose to block.
Is this workflow acceptable? If not, how can I stop a thread's process when I don't need it no more (or how can I abandon it)?
Don't use terminate(), read the warning in the documentation.
Whil it is possible to restart a QThread, restarting threads usually is not a good idea, there should be a better solution to do what you're trying to do.
It seems that in some cases, the thread becomes unusable after termination, and isRunning() and isFinished() may hang the calling thread, even if called only after the TERMINATED signal.
My workaround was to terminate a thread, forget about it and start a new one.
Given a System.Timers.Timer, is there a way from the main thread to tell if the worker thread running the elapsed event code is still running?
In other words, how can one make sure the code running in the worker thread is not currently running before stopping the timer or the main app/service thread the timer is running in?
Is this a matter of ditching Timer for threading timer using state, or is it just time to use threads directly?
Look up ManualResetEvent, as it is made to do specifically what you're asking for.
Your threads create a new reset event, and add it to an accessible queue that your main thread can use to see if any threads are still running.
// main thread owns this
private List<ManualResetEvent> _resetEvents;
...
// main thread does this to wait for executing threads to finish
WaitHandle.WaitAll(_resetEvents.ToArray(), 2000, false)
...
// worker threads do this to signal the thread is done
myResetEvent.Set();
I can give you more sample code if you want, but I basically just copied it from the couple articles I read when I had to do this a year ago or so.
Forgot to mention, you can't add this functionality to the default threads you'll get when your timer fires. So you should make your timer handler be very lean and do nothing more than prepare and start a new worker thread.
...
ThreadPool.QueueUserWorkItem(new WaitCallback(MyWorkerDelegate),
myCustomObjectThatContainsAResetEvent);
For the out of the box solution, there is no way. The main reason is the thread running the TimerCallback function is in all likelihood still alive even if the code running the callback has completed. The TimerCallback is executed by a Thread out of the ThreadPool. When the task is completed the thread does not die, but instead goes back into the queue for the next thread pool task.
In order to get this to work your going to have to use a manner of thread safe signalling to detect the operation has completed.
Timer Documentation