flat assembler
Message board for the users of flat assembler.

Index > Windows > WaitForSingleObject / TerminateThread (?)

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

Do I have absolutely call "WaitForSingleObject" before "TerminateThread" ?

When should i call "WaitForSingleObject" before ending a thread?

thank you all
Embarassed

EDIT by DOS386: Moved from Main to Windows

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 23 Dec 2010, 14:47
View user's profile Send private message Send e-mail Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Actually you don't have to call TerminateThread always. If the thread ends normally, there is no reason to call TerminateThread.
You should use WaitForSingleObject only when you have to wait for thread to finish it's job. For example, if the main thread can't continue without the result of the thread. If you wait always it is useless to use thread - you can do the job in the main thread, instead of waiting.
Post 23 Dec 2010, 14:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17476
Location: In your JS exploiting you and your system
revolution
JohnFound wrote:
For example, if the main thread can't continue without the result of the thread. If you wait always it is useless to use thread - you can do the job in the main thread, instead of waiting.
Only if you are not synchronising something. It could be that the main thread finishes a parallel task before another thread and needs to wait. Perfectly normal and acceptable behaviour.
Post 23 Dec 2010, 15:08
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Quote:

If you wait always, it is useless to use thread,
you can do the job in the main thread, instead of waiting.

Here is a sentence that perfectly explains the usefulness of this function.
perfect, I understood. Thank you very much JohnFound
Quote:

Only if you are not synchronising something. It could be that the main thread finishes a parallel task before another thread and needs to wait. Perfectly normal and acceptable behaviour.

I also understand that. thank you revolution.
(there is no synchronization in my case)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 23 Dec 2010, 15:13
View user's profile Send private message Send e-mail Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
when you create thread, you must take responsibility for it, by for example registering waitforsingleobject. Thread that created child thread must be notyfied when it exitted (was killed?). You shouldnt just spawn thread and forget about it, hoping it will complete a job. When you write multithreaded app, 1 thread is always main thread wich only watch over its children and manage them,
Post 23 Dec 2010, 20:54
View user's profile Send private message Reply with quote
Igor1024



Joined: 12 Dec 2010
Posts: 19
Igor1024
Actually, "TerminateThread" function is rather bad for using, cause it can lead to leaks (read Jeffrey Richter ).
Post 24 Dec 2010, 06:37
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.