Explanation & Answer
bro let me know if you have any doubts or issues.
Page number - 364
Question 1. what does thread's run method do ?
In Python, the thread path is the thread's entry point. When you create a new thread in Pyt
hon, you can assign a target function to be executed in a control thread. If you don't provid
e a target function, the thread path will be called.
The path contains the code that the thread will execute. When a thread is started by calling
the Start method or using a primitive such as Thread or ThreadPoolExecutor, the thread's
worker method is called.
By default, the path is empty. If you want the thread to perform some action you should ov
erride the running method and add your own code. For example, you can use the run meth
od to use a loop that reads continuously from a socket, or to do some calculations that tak
e a long time to complete.
Question 2 what is time slicing ?
Time slicing is a scheduling operation used by the operating system to allocate a fixed am
ount of time to each process or thread on the system. In a time slot, the operating system
switches between running all processes or threads quickly for a short period of time, called
a time slot or time slot, before switching to another hole. This gives the illusion that every
process or thread is running at the same time.
Time slicing is used to allow multiple processes or threads to share the CPU and only one
instruction can be executed at a time. By quickly switching between processes or threads,
the operating system can make it appear as if each process or thread has its own CPU, ev
en if they all share the same hardware.
The length of each time slot may vary depending on the operating system and system load
. The overall time is in milliseconds, and the operating system switches between processe
s or threads hundreds or thousands of times per second. One benefit of the
time slot is that it allows the operating system to give every process or thread a fair share
of the CPU, regardless of its priorities. It also helps prevent a process or thread from runni
ng on the CPU and starving other processes or resource threads.
However, time slicing adds overhead because the process must constantly switch betwee
n processes or threads. Sometimes this can lead to poor performance or even poor realtime performance.
Question 3 what is synchronization problem ?
In computer science, synchronization problems arise when multiple threads or processes a
ttempt to access a shared resource such as memory or data at the same time. This can le
ad to competition, death and other related diseases.
Synchronization problems occur because many threads or processes can run at the same
time and it is difficult to control their actions and ensure that they do not interfere with each
other. For example, if two threads try to write to the same memory location at the same ti
me, the result may be arbitrary or ambiguous.
One solution to synchronization problems is to use synchronization primitives such as lock
s, semaphores, and clocks.
These primitives provide a way to control access to shared resources by allowing only one
thread or process to access the resource at a time. For example, locks can be used to en
sure that only one thread has access to a critical section of code at any given time.
However, using sync primitives introduces additional complexity and overhead, and increa
ses the risk of deadlocks and other errors. Therefore, synchronization problems will be diffi
cult to solve, especially in large complex systems.
To avoid synchronization problems, it is important and good to design systems and applica
tions that minimize the need for shared resources or to use synchronization methods corre
This often requires careful design as well as rigorous testing and analysis to ensure it work
s as well as possible.
Question 4 what is the difference between a sleeping thread and a waiting thread ?
In Python and other programming languages, there are two ways to suspend the execution
of a thread: put it to sleep or make it standby.
A sleeper thread is a thread that is instructed to suspend execution for a specified period o
f time before resuming execution. In the meantime, the thread is blocked and cannot do an
y other work until the sleep time has passed. In Python, the time.sleep() function can be us
ed to put a thread to sleep.
Sleeper threads are useful in situations where the thread needs to wait a certain ...