Page 71 - DCAP403_Operating System
P. 71
Operating System
Notes a specific amount of processor time and when its time got over the second program standing in
queue was called upon (this is called Multi-tasking, and you would learn more about it soon).
Each running program (called the process) had its own memory space, its own stack, heap and its
own set of variables. One process could spawn another process, but once that occurred the two
behaved independent of each other. Then the next big thing happened. The programs wanted
to do more than one thing at the same time (this is called Multi-threading, and you would learn
what it is soon). A browser, for example, might want to download one file in one window, while
it is trying to upload another and print some other file. This ability of a program to do multiple
things simultaneously is implemented through threads (detailed description on threads follows
soon).
Multi-tasking vs. Multi-threading
Multi-tasking is the ability of an operating system to execute more than one program
simultaneously. Though I say so but in reality no two programs on a single processor machine
can be executed at the same time. The CPU switches from one program to the next so quickly that
appears as if all of the programs are executing at the same time. Multi-threading is the ability of
an operating system to execute the different parts of the program, called threads, simultaneously.
The program has to be designed well so that the different threads do not interfere with each
other. This concept helps to create scalable applications because you can add threads as and
when needed. Individual programs are all isolated from each other in terms of their memory and
data, but individual threads are not as they all share the same memory and data variables. Hence,
implementing multi-tasking is relatively easier in an operating system than implementing multi-
threading.
4.10 Thread Libraries
The threads library allows concurrent programming in Objective Caml. It provides multiple
threads of control (also called lightweight processes) that execute concurrently in the same
memory space. Threads communicate by in-place modification of shared data structures, or by
sending and receiving data on communication channels.
The threads library is implemented by time-sharing on a single processor. It will not take
advantage of multi-processor machines. Using this library will therefore never make programs run
faster. However, many programs are easier to write when structured as several communicating
processes.
Two implementations of the threads library are available, depending on the capabilities of the
operating system:
1. System threads: This implementation builds on the OS-provided threads facilities: POSIX
1003.1c threads for Unix, and Win32 threads for Windows. When available, system threads
support both bytecode and native-code programs.
2. VM-level threads: This implementation performs time-sharing and context switching at the
level of the OCaml virtual machine (bytecode interpreter). It is available on Unix systems,
and supports only bytecode programs. It cannot be used with native-code programs.
Programs that use system threads must be linked as follows:
ocamlc -thread other options unix.cma threads.cma other files
ocamlopt -thread other options unix.cmxa threads.cmxa other files
POSIX 1003.1c threads for Unix, for windows which thread available.
64 LOVELY PROFESSIONAL UNIVERSITY