Ryan Saptarshi Ray et al. Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 5, Issue 3, ( Part -1) March 2015, pp.04-08 www.ijera.com 4 | Page Synchronizing Parallel Tasks Using STM Ryan Saptarshi Ray, Utpal Kumar Ray, Surojit Mondal, Parama Bhaumik Junior Research Fellow Department of Information Technology Jadavpur University, Kolkata, India Associate Professor Department of Information Technology Jadavpur University, Kolkata, India B.E.(I.T.) Final Year Student Department of Information Technology Jadavpur University, Kolkata, India Assistant Professor Department of Information Technology Jadavpur University, Kolkata, India Abstract The past few years have marked the start of a historic transition from sequential to parallel computation. The necessity to write parallel programs is increasing as systems are getting more complex while processor speed increases are slowing down. Current parallel programming uses low-level programming constructs like threads and explicit synchronization using locks to coordinate thread execution. Parallel programs written with these constructs are difficult to design, program and debug. Also locks have many drawbacks which make them a suboptimal solution. One such drawback is that locks should be only used to enclose the critical section of the parallel-processing code. If locks are used to enclose the entire code then the performance of the code drastically decreases. Software Transactional Memory (STM) is a promising new approach to programming shared-memory parallel processors. It is a concurrency control mechanism that is widely considered to be easier to use by programmers than locking. It allows portions of a program to execute in isolation, without regard to other, concurrently executing tasks. A programmer can reason about the correctness of code within a transaction and need not worry about complex interactions with other, concurrently executing parts of the program. If STM is used to enclose the entire code then the performance of the code is the same as that of the code in which STM is used to enclose the critical section only and is far better than code in which locks have been used to enclose the entire code. So STM is easier to use than locks as critical section does not need to be identified in case of STM. This paper shows the concept of writing code using Software Transactional Memory (STM) and the performance comparison of codes using locks with those using STM. It also shows why the use of STM in parallel-processing code is better than the use of locks. Keywords- Parallel Programming; Multiprocessing; Locks; Transactions; Software Transactional Memory I. INTRODUCTION Generally one has the idea that a program will run faster if one buys a next-generation processor. But currently that is not the case. While the next- generation chip will have more CPUs, each individual CPU will be no faster than the previous year’s model. If one wants programs to run faster, one must learn to write parallel programs as now multi-core processors are becoming more and more popular. The past few years have marked the start of a historic transition from sequential to parallel computation. The necessity to write parallel programs is increasing as systems are getting more complex while processor speed increases are slowing down. Parallel Programming means using multiple computing resources like processors for programming so that the time required to perform computations is reduced [1]. II. BUS TICKET COUNTER PROBLEM In the Bus Ticket Counter Problem initially only one counter is open from which passengers may purchase tickets. As more counters open the options for the passengers (counters from which they can purchase tickets) increases, hence the time taken for purchasing tickets decreases. The problem is to synchronize the operations of the different counters so that the passengers do not have to face any delay. III. BUS TICKET COUNTER PROBLEM USING LOCKS The hardest problem that should be overcome when writing parallel programs is that of synchronization. Multiple threads may need to access the same locations in memory and if careful measures are not taken the result can be disastrous. If two threads try to modify the same variable(s) at the same time, data can become corrupt. Currently locks are used to solve this problem. Locks ensure that a critical section, which is a block of code that contains variable(s) that may be accessed by multiple threads, can only be accessed by one thread at a time. When a thread tries to enter a critical section, it must first acquire that section's lock. If another thread is already holding the lock, the former thread must wait until the RESEARCH ARTICLE OPEN ACCESS