Search This Blog

Tuesday, December 21, 2010

Threads in perl

Perl Threads
Define thread?
A computer runs many applications at once, each instance of an application is known as a process. Each process is made of 1 or more threads, each thread is a sequence of code, this code is often responsible for one aspect of the program, or one task a program has been given.
For instance a program doing a complex long calculation may split into two threads, one to keep a user interface responsive, and one (or more) to progress through the lengthy calculation.


Thread Concept in Perl
Thread is an execution flow.
Single threaded programs have a single execution point (execution context) at any given time.
Multi-threaded programs have multiple execution points, i.e. different parts of the code may be executed at the same time.
Perl threads are different from most of the other thread models.
Default no data is shared. All data is copied on the thread creation.

Features of Thread
1. Parallel, independent code part to may be executed on different processes.
2. Shared memory, different threads may share the same data.
3. The program more responsible by proper division to threads.

Drawbacks of Thread
1. Synchronization
2. Debugging
3. Deadlock

No comments:

Post a Comment