Ppi Multithreading
Ppi Multithreading
1. Kernel Threads
2. User-space threads or User threads
Advantages of Thread:
Thread plays a major role in application programming. All the GUI programs and web
servers are threaded together. The main reasons for using threads are:
Parallel Computation: If any user has multiprocessor machine then the thread can
allow doing parallel processing with the goal of increase in processing speed.
Standardization: It became a standard approach for all programming languages
as it increases programming speed.
Parallel I/O (Input/Output): When we talk about the speed of input & output, it is
comparatively slow in CPU. By placing each i/o operations in multiple individual threads,
programmers can make use of operations done in parallel with each other & with the
computation speed.
Asynchronous Events: Multiple threaded applications can deal with asynchronous
actions. For example in a program, programmers may don't know whether the next
action will be to use the mouse or to use the keyboard. By planting a separate thread
for each action i.e. two threads both for mouse and keyboard, programmers can able to
code a cleaner, efficient application which is to use non-blocking I/O operations.
1. thread module
2. threading module
NOTE: the module 'thread' treats the thread like a function whereas the 'threading' is
implemented as an object.
Benefits Of Threading
1. For a single process, multiple threads can be used to process and share the same
data-space and can communicate with each other by sharing information.
2. They use lesser memory overhead and hence they are called lightweight
processes.
3. A program can remain responsive to input when threads are used.
4. Threads can share and process the global variable's memory.
In a thread, there are three different parts. It has the beginning, an execution part, and a
conclusion. It also has an instruction pointer that points to where the thread or process is
currently running and hence the thread is able to run several different program blocks
concurrently.
A thread is an entity within a process that can be scheduled for execution. Also, it is the smallest
unit of processing that can be performed in an OS (Operating System).
isDaemon() method
This method is used to get the value of the thread's daemon flag.
setDaemon(daemonic) method
This method is used to set the thread's daemon flag to the Boolean value daemonic.
This must be called before start() method is called.
The entire Python program exits when no active non-daemon threads are left.
Using Locks