answersLogoWhite

0

Every process has at least one thread, known as the main thread. However, threads can spawn other threads of execution. All threads within a process share the same data segment (constants, static variables and global variables) and the same virtual address space. However each has its own independent stack. All active threads in a process get an equal share of CPU time, thus they operate concurrently. If the system has multiple cores, separate threads can also operate simultaneously.

In multi-tasking environments, concurrent threads are vital. For instance, rather than the main thread performing tasks it can initialise its environment and then enter an "idle mode", a tight loop that simply monitors a message queue and dispatches those messages accordingly. If a message indicates that a lengthy task must be performed, the main thread would be unable to monitor the message queue for the duration of that task and the application becomes unresponsive to user-input while that task is going on. But if the task is delegated to a "worker thread", the main thread can continue to accept user-input. Meanwhile the worker thread can complete its task and signal the main thread via the message queue.

The only problem is that if the main thread is terminated (perhaps the user decided to end the program in the middle of a task), it must signal all worker threads to abort before the main thread can end. To achieve this, the main thread simply posts messages for each of its threads onto its own queue. When one of these messages reaches the front of the queue it will simply ignore it. Meanwhile the worker threads will periodically examine the queue to see if there are any messages intended for it and process them accordingly, removing them from the queue and signalling the message queue when they've completed the abortion. Once all workers have signalled that they have aborted, the main thread can safely terminate.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

Differences between cgi and servlet?

CGI creates process for each client call where as servlet creates process for the first time and then uses thread for each client.


What is the difference between a computer process and thread in microprocessor?

A thread is a sub process in other words one process can contain multiple threads.


What is the difference between a process and thread?

The same metaphor: the difference of a person (thread) and a family (process) A process has at least 1 thread and may have many threads, while 1 thread must live within a process


Is thread as used by Intel in their marketing for Hyper-Threading Technology same as the thread that is talked about when discussing the difference between a process and a thread?

No.


What is the difference between process and thread?

Basically no difference, except that process can use many threads; thread can use only one.


Can a thread create a process?

No, a thread can't create aprocess, because the environment of the thread is a part of a process which created this thread.


Can a thread be called a process or vise versa?

No. A thread is a part of a process, but a process can not be part of a thread. Processes are always "at the top."


What is a thread in computers?

Execution context within a process is called Thread. Threads run, process does not. Every process starts with one thread.


What is the difference between thread based and process based?

Process based is much time as comparison as thread based. as well as Thread based application is cost effective. Process based application has its own address space so it take more cost. Alok Gupta. India.


What are the advantages in political process?

Differences between public administration and political process?


What is dfference between synchronization and asynchronization in java with example?

synchornisation is the process where more than one thread can be accessed by accesssing the shared object of the class.By syncornisation we can have the communication between threads.if one thread works then another thread automatically stops


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.