answersLogoWhite

0

To end a thread within the thread's own code you can also simply return from the thread function or method.

However if you want to terminate a thread from code which is running outside of the thread's own flow you must typically code a mechanism of your own to do this. A simple way to do this is to have the threaded code check a shared signal variable every so often, if the variable is signaled - then the threaded code exits and the thread dies.

Terminating a process (in C with say exit(..) ) will typically force the closing of any associated threads.

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Computer Science
Related Questions

How do you terminate a thread which is continuously executing?

A thread that is continuously executing has an infinite loop. To terminate that thread you must break that loop by providing a suitable terminating condition. If the thread is a "worker" thread, the main thread should signal all worker threads to terminate when the main thread terminates. The main thread should remain active until all worker threads have successfully terminated.


If a process terminates will its thread also terminate?

yes, because if process is terminated then its related thread has no work. After completion of process the kernel generates a thread that will cancelled the thread in order to save the time and memory of CPU.


If a process terminates will its thread also terminates?

Yes, the thread will also terminate if the process it is running in terminates. The thread is dependent upon the processes it is running. If the processes die the thread dies.


What is ment by thread interaction in java?

Two threads can interact with one another using the wait and notify methods. If one thread wants another thread to wait until it completes, it can use the wait method. similarly if it wants the other threads to know that it is done executing, it can use the notify or notifyall methods


What happens to child thread when you delete main thread during run-time?

In Java, if the main thread somehow exits then all other threads will stop executing. This generally does not happen, as the main thread will wait for all child threads to terminate before the main thread itself finishes. Interrupting this process is hard to do short of an un-handled exception or a call to System.exit. If the child thread is also a daemon thread, then the child thread will continue to execute. If the child thread is a normal thread then, the moment System.exit is called, the child thread also terminates If you call the join() method from the child thread, then the main thread will wait until the child is over before executing the System.exit


If process stop its execution will thread also stop or it will continue to run?

Processes do not execute, it is the threads within a process that actually execute. All processes have at least one thread of execution, the main thread. If the main thread falls from scope, the process ends, taking all threads with it. This can lead to undefined behaviour if the threads are not terminated gracefully from within the main thread before it falls from scope.


Can a method be static and synchronized?

Yes. In Java methods can be static and synchronized. Static methods access other static members in the class. Static in case of inheritance are treated as non - static. Synchronized methods are those which have dedicated thread attached to it and no other can access until currrent thread leaves the control from it.


What is conditional critical region in os?

it is the part of code where shared resources are updates..that can be accessed by one or more then one thread of execution.It is usually terminate in a fixed time.


What methods are used to terminate electrical equipment?

Crimp on wire ends are the most common.


If Runnable interface is better than Thread class than why you are using Thread class What is the need for Thread class?

Though implementing Runnable interface is better approach than inheriting from Thread class but there are certain methods available in Thread class like join,sleep or yield which does not available in Runnable interface and programmer can not use them unless he has object of Thread class. This is why we should have Thread class Object. Rupesh Raghani


What are the synchronized methods and synchronized statements in java?

Synchronized Methods are methods that have the keyword synchronized in the method signature. Synchronized statements are pieces of java code that are surrounded by brackets which have the keyword synchronized qualifying them. Both cases mean that - only one thread will be able to access the method or the statement that is synchronized


Can you synchronize a class?

No. If someone refers to a "synchronized class," they are generally talking about a class in which all methods are thread-safe.