Operating System/O.S(Neso Academy, HPC Lab. KOREATECH)

10)Threading issue (fork , cancellation) , CPU and I/O burst cycles

Tony Lim 2021. 5. 10. 13:56
728x90

Issue

if one thread in a program calls fork(), does the new prcoess duplicate all threads,
or is the new process single-threaded?

solution

some unix systems have chose to have 2 versions of fork(), one that duplicates all threads and
another that duplicates only the thread that invoked the fork() system call.

in muti thread process if one of thread invokes exec() system call, the program specified in the parameter to exec() will replace the entire prcoess including all threads.

 

which fork() should we use?

If exec() is called immediately after forking = duplicating all thread is unneccssary as program specified in the parameters to exec() will replace the process. 

if the separate process does not call exec() after forking = separate process( forked process) should duplicate all threads


Thread cancellation = terminating a thread before it has completed. 

target thread = thread that is to be canceled.

examples

  • if mutiple threads were concurrently searching through a database and one thread returns the result , the remaining threads might be canceld.
  • when a user press a button on a web browser that stops a web page from loading any further, all threads loading the page are canceled.

Asynchronous cancellation = one thread immediately terminates the target thread.

Deferred cancellation = the target thraed periodically checks whether it should terminate , allowing it an opportunity to terminate itself in an orderly fashion. 

 

Issue

1. Resouces have been allocated to a canceled thread

2. a thread is canceled while in the midst of updating data it is sharing with other threads

Often OS will reclaim system resources from a canceled thread but will not reclaim all resources. asynchronous cancellation may not free a system-wide resources.

using Deferred cancellation is better = after target threads determines that it can cancel safely that it will be cancel.

 

CPU and I/O burst cycles

Process execution consists of a cycle of CPU execution (CPU burst) and I/O wait (I/O burst). 

first CPU burst -> I/O burst and it repeats until final CPU burst ends with a system request to terminate execution.

 

 

 

 

728x90