Multithreading Essay

860 Words2 Pages

Introduction
Multithreading is the ability of an operating system to run programs concurrently that are divided into sub parts or threads. It is similar to multitasking but instead of running on multiple processes concurrently, multithreading allows multiple threads in a process to run at the same time. Threads are more basic and smaller unit of instruction. Hence multithreading can occur within a single process. Multithreading can also be defined as a combination of microprocessor design and machine code which allows computer instructions to be carried out concurrently and the results to be combined in right logical order. Programs can execute multiple tasks simultaneously by incorporating multithreading. The real purpose of multithreading is to help in proper and resource effective utilization of the hardware and software resources. Multithreading provides concurrency as it enables many programs to run in parallel and execute simultaneously thus saving time and providing efficiency (Ball et al., 2011).
Operating systems are running multiple threads at one time in background, for example, logging file changes, indexing data and managing the operating systems. At the same time, web browsers also support multithreading. Users can open multiple web pages running animations in different tabs in a web browser concurrently. Multiple threads running simultaneously don’t affect each other as long as the CPU has enough power to run all of them. Multithreading adds stability to the programs and prevent it from crashing. All threads run independently. So if an error is encountered by a thread, it should not affect rest of the program. It allows better utilization of the processor and other system resources (Blumofe et al., 1996).
Proposed W...

... middle of paper ...

...gram consists of a class named Test Account which contains a method called Run. The Run method is to test another class called Account in a multithreaded fashion. Consider an instance of class Account with value $10. Then consider a child thread in which $2 are being withdrawn from the account. The main thread starts the child thread and two operations are being performed concurrently on the account; one is withdrawing $2 from the account and the other is depositing $1 in the account. The main thread then waits for the child thread to complete. Since the two operations that are withdrawal and deposit of money are executing in parallel so when we will withdraw $2 from the account, $8 will be left in the account but at the same time we are also depositing $1 in the account therefore the expected amount to be present in the account at the end is $9 but it is not so.

More about Multithreading Essay

Open Document