What is Multi-threading?

The Concept of running multiple instances of a certain process can be termed as multi-threading. A Process is the basic block of a running program, the unit of execution of a process is a thread.

A process with a single unit of execution is termed a single threaded process and a process that runs more than one instance of itself is termed a multi-threaded process. Let us try and understand Multi-threading using the below context.

An operating system provides two OS concepts that provide an user the illusion that a particular program is utilizing the entire resources of the Operating system . They are (From Linux system Programming – Robert Love) 

  • Virtualized memory
  • Virtual processor

virtual memory – provides an abstraction between HW memory and the memory that a process sees. It provides an interface in which each process can seamlessly interact with HW memory. 

Virtual processor – each process gets a short slice of time in which is scheduled to operate. Hence, all processes (and threads in a process) gets there unique slice of operation. Hence, each process and its threads of execution are running simultaneously giving the illusion that the processor is serving a specific process/thread only.

For a process that is running multiple threads – the virtual memory allocated to a process is shared by all threads spawned by that process. the global memory used by all the threads is the same. The below image from the previous article  would provide the context of a multi-threaded process.

Fig Courtesy: Linux Programming Interface – Michael Kerrisk

We will look at the pros and cons of multi-threaded programming in the next article.

References:

  • The Linux Programming Interface – Michael Kerrisk
  • Linux System Programming – Robert Love

Advantages and Disadvantages of threads

Comments

  1. Pingback: Threads in Linux | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *