Venkat Reddy
Background -A running program is called a "process". Each process has memory, list of open files, stack, program counter, etc...Normally, a process executes statements in a single sequence of control-flow.
Process creation with fork(),system(), popen(), etc... -These commands create an entirely new process.Child process runs independently of the parent.Has own set of resources.There is minimal sharing of information between parent and child.Think about using the Unix shell.
Threads -A thread is kind of like a process (it's a sequence of control-flow).Except that it exists entirely inside a process and shares resources.A single process may have multiple threads of execution.Useful when an application wants to perform many concurrent tasks on shared data.Think about a browser (loading pages, animations, etc.)
Problems with Threads
Scheduling -To execute a threaded program, must rapidly switch between threads.This can be done by the user process (user-level threads).Can be done by the kernel (kernel-level threads).
Resource Sharing -Since threads share memory and other resources, must be very careful.Operation performed in one thread could cause problems in another.
Synchronization -Threads often need to coordinate actions.Can get "race conditions" (outcome dependent on order of thread execution)Often need to use locking primitives (mutual exclusion locks, semaphores, etc...)
Python Threads
Python supports threads on the following platforms
* Solaris
* Windows
*Systems that support the POSIX threads library (pthreads)
Thread scheduling -Tightly controlled by a global interpreter lock and scheduler.Only a single thread is allowed to be executing in the Python interpreter at once.Thread switching only occurs between the execution of individual byte-codes.Long-running calculations in C/C++ can block execution of all other threads.However, most I/O operations do not block.
Comments -Python threads are somewhat more restrictive than in C.Effectiveness may be limited on multiple CPUs (due to interpreter lock).Threads can interact strangely with other Python modules (especially signal handling).Not all extension modules are thread-safe.
The thr