SlideShare a Scribd company logo
1 of 5
Download to read offline
Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com 
ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 
www.ijera.com 13 | P a g e 
Railway Ticket Counter Problem With STM Mohit Kumar Modi, Utpal Kumar Ray, Ryan Saptarshi Ray, Parama Bhaumik BE(IT) Third year Student Department of Information Technology, Jadavpur University Kolkata, India Associate Professor Department of Information Technology, Jadavpur University ,Kolkata,India Junior Research Fellow 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. RAILWAY TICKET COUNTER PROBLEM 
In the Railway 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. RAILWAY 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
Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com 
ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 
www.ijera.com 14 | P a g e 
lock-holding thread releases the lock, which it does when it leaves the critical section [2]. In the parallel program using threads and locks which solves the Railway ticket-counter problem the time taken for processing of passenger’s request at each counter(x) and the number of passengers at each counter(y) are taken as input. There is one thread function-“tctr()”. The following code snippet shows the tctr thread: void *tctr(int *num_ptr) { unsigned long j; int num,*number_ptr; number_ptr=num_ptr; num=*number_ptr; pthread_mutex_lock(&mutex1); arr[num]=x*y; if(arr[num]<=proc) { proc= arr[num]; if(x<prev_bestproc) { prev_bestproc=x; } } pthread_mutex_unlock(&mutex1); pthread_exit(0); } In the thread “tctr” the amount of time for which the passenger has to wait to purchase ticket from that counter is calculated by the following code snippet: pthread_mutex_lock(&mutex1); arr[num]=x*y; if(arr[num]<=proc) { proc= arr[num]; if(x<prev_bestproc) { prev_bestproc=x; } } pthread_mutex_unlock(&mutex1); pthread_exit(0); 3 lock calls are being used in the program. pthread_mutex_init(&mutex1,NULL), is used for lock initialization. 
pthread_mutex_lock(&mutex1), is used for locking. This means that any thread which needs to access the critical section has to first acquire the lock on mutex1. 
pthread_mutex_unlock(&mutex1), is used for unlocking. In the program the region where more than one thread may access the global array arr at the same time is the critical section. Thus this region is enclosed within locks. Hence there is no synchronization problem in the above code. 
IV. EXPERIMENTAL RESULTS FOR RAILWAY TICKET-COUNTER PROBLEM USING LOCKS 
The following table shows the experimental results for Railway ticket-counter problem using locks: 
NUMBER OF THREADS 
TIME TAKEN( SEC) 
SPEEDUP 
EFFICIENCY 
1 
12 
1 
1.00 
2 
6 
2 
1.00 
3 
4 
3 
1.00 
4 
3 
4 
1.00 
5 
3 
4 
0.80 
6 
2 
6 
1.00 
7 
2 
6 
0.86 
8 
2 
6 
0.75 
9 
2 
6 
0.67 
10 
2 
6 
0.60 
11 
2 
6 
0.55 
12 
1 
12 
1.00 
The corresponding graphs for the above experimental results are shown below: From the above graph we can see that as the number of threads increases the time taken decreases.
Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com 
ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 
www.ijera.com 15 | P a g e 
From the above graph we can see that as the number of threads increases the speedup also steadily increases. From the above graph we can see that as the number of threads increases the efficiency varies around 1. 
V. RAILWAY TICKET-COUNTER PROBLEM USING STM 
The synchronization problem can also be solved using STM. If STM is used in a program then we do not have to use locks in the program. Thus the problems which occur due to the presence of locks in a program do not occur in this type of code. The critical section of the program has to be enclosed within a transaction. Then STM by its internal constructs ensures synchronization in the program. The structure of the program using threads and STM which solves the railway ticket-counter problem is same as that of the program using threads and locks. The only difference is that STM is being used in this program. The following code snippet shows the tctr thread: void *tctr(int *num_ptr) { unsigned long j; unsigned char byte_under_stm; int num,*number_ptr; number_ptr=num_ptr; num=*number_ptr; 
stm_init_thread(); 
START(0,RW); byte_under_stm=(unsigned char) LOAD(&arr[num]); byte_under_stm=x*y; if(byte_under_stm<=proc) { proc= byte_under_stm; if(x<prev_bestproc) prev_bestproc=x; } STORE(&arr[num],byte_under_stm); COMMIT; stm_exit_thread(); pthread_exit(0); } The STM functions and calls which have been used in the code are explained below: stm_init is used to initialize the TinySTM library at the outset. It is called from the main thread before accessing any other functions of the TinySTM library. stm_init_thread is used to initialize each thread that will perform transactions. It is called once from each thread that performs transactional operations before the thread calls any other functions of the TinySTM library. In this program it is called from the thread tctr. stm_exit is the corresponding shutdown function for stm_init. It cleans up the TinySTM library. It is called once from the main thread after all transactional threads have completed execution. stm_exit_thread is the corresponding shutdown function for stm_init_thread. It cleans up the transactional thread. It is called once from each thread that performs transactional operations upon exit. In this program it cleans up the thread tctr. START(0,RW) is used to start a transaction. In this program it is used in the thread tctr. COMMIT is used to close the transaction. In this program it is used in the thread tctr. byte_under_stm=(unsigned char) LOAD(&arr[num]); stores the value of arr[num] in byte_under_stm. In this program it is used in the thread tctr.
Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com 
ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 
www.ijera.com 16 | P a g e 
STORE(&arr[num],byte_under_stm); stores the value of byte_under_stm in arr[num]. In this program it is used in the thread tctr. In this program the region where more than one thread may access the global array arr at the same time is the critical section. Thus this region is enclosed within transaction using TinySTM which is a type of STM. Hence there is no synchronization problem in the above code. 
VI. EXPERIMENTAL RESULTS FOR RAILWAY TICKET-COUNTER PROBLEM USING STM 
The following table shows the experimental results for railway ticket-counter problem using STM: 
NUMBER OF THREADS 
TIME TAKEN (SEC) 
SPEEDUP 
EFFICIENCY 
1 
12 
1 
1.00 
2 
6 
2 
1.00 
3 
4 
3 
1.00 
4 
3 
4 
1.00 
5 
3 
4 
0.80 
6 
2 
6 
1.00 
7 
2 
6 
0.86 
8 
2 
6 
0.75 
9 
2 
6 
0.67 
10 
2 
6 
0.60 
11 
2 
6 
0.55 
12 
1 
12 
1.00 
The corresponding graphs for the above experimental results are shown below: 
From the above graph we can see that as the number of threads increases the time taken decreases. 
From the above graph we can see that as the number of threads increases the speedup also steadily increases. From the above graph we can see that as the number of threads increases the efficiency varies around 1. 
VII. PERFORMANCE COMPARISION OF LOCKS AND STM 
From the above experimental results we see that performance of locks and STM are similar. In the code with locks we have enclosed only the critical section with locks. When we enclosed the entire code with locks then the performance drastically decreased. In the code with STM also we have enclosed only the critical section with STM. When we enclosed the entire code with STM then also the performance remained same. So it can be said that performance of STM is better than that of locks. Also we can say that STM is easier to use than locks as critical section need not be identified in case of STM. 
VIII. CONCLUSION 
STM has been shown in many ways to be a good alternative to locks for writing parallel programs. STM provides a time-tested model for isolating concurrent computations from each other. This model raises the level of abstraction for reasoning about
Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com 
ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 
www.ijera.com 17 | P a g e 
concurrent tasks and helps avoid many parallel programming errors. This paper has discussed how STM can be used to solve the problem of synchronization in parallel programs. STM has ensured that lock-free parallel programs can be written. This ensures that the problems which occur due to the presence of locks in a program do not occur in this type of code. It has also been shown that STM is easier to use than locks as critical section need not be identified explicitly in case of STM. In case of STM if the entire code is enclosed within STM the performance of the code is same as that of the code in which only the critical section is enclosed within STM. But in case of locks if the entire code is enclosed within locks then the performance decreases sharply. So it has been shown that the performance of STM is much better than that of locks. Many aspects of the semantics and implementation of STM are still the subject of active research. While it may still take some time to overcome the various drawbacks, the necessity for better parallel programming solutions will drive the eventual adoption of STM. Once the adoption of STM begins it will pick up momentum and make a very large impact on software development in the long run. In the near future STM will become a central pillar of parallel programming. 
REFERENCES 
[1] Simon Peyton Jones, “Beautiful concurrency”. 
[2] Elan Dubrofsky, “A Survey Paper on Transactional Memory”. 
[3] Pascal Felber, Christof Fetzer, Torvald Riegel, “Dynamic Performance Tuning of Word-Based Software Transactional Memory”. 
[4] http://en.wikipedia.org/wiki/Transactional_ memory 
[5] James Larus and Christos Kozyrakis. “Transactional Memory” 
[6] Pascal Felber, Christof Fetzer, Patrick Marlier, Torvald Riegel, “Time-Based Software Transactional Memory” 
[7] Tim Harris, James Larus, Ravi Rajwar, “Transactional Memory” 
[8] Mathias Payer, Thomas R. Gross, “Performance Evaluation of Adaptivity in Software Transactional Memory” 
[9] Kevin E. Moore, Jayaram Bobba, Michelle J. Moravan, Mark D. Hill, David A. Wood., “LogTM: Log-based Transactional Memory” 
[10] Dave Dice , Ori Shalev , Nir Shavit., “Transactional Locking II” 
[11] http://tmware.org 
[12] Maurice Herlihy, J. Eliot B. Moss, “Transactional Memory: Architectural Support for Lock-Free Data Structures”. 
[13] Martin Schindewolf, Albert Cohen, Wolfgang Karl, Andrea Marongiu, Luca Benini, “Towards Transactional Memory Support for GCC”. 
[14] Virendra J. Marathe, Michael F. Spear, Christopher Heriot, Athul Acharya, David Eisenstat, William N. Scherer III, Michael L. Scott, “Lowering the Overhead of Nonblocking Software Transactional Memory”. 
[15] Utku Aydonat, Tarek S. Abdelrahman, Edward S. Rogers Sr., “Serializability of Transactions in Software Transactional Memory”. 
[16] Maurice Herlihy, Nir Shavit, “The Art of Multiprocessor Programming”. 
[17] Brendan Linn, Chanseok Oh, “G22.2631 project report: software transactional memory”. 
[18] http://en.wikipedia.org/wiki/Software_transactional_memory 
[19] http://research.microsoft.com/~simonpj/papers/stm/ 
[20] http://www.haskell.org/haskellwiki/Software_transactional_memory. 
[21] Ryan Saptarshi Ray, “Writing Lock-Free Code using Software Transactional Memory ”. 
[22] Ryan Saptarshi Ray,Utpal Kumar Ray “Different Approaches for improving performance of Software Transactional Memory ”.

More Related Content

Viewers also liked

Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...
Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...
Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...IJERA Editor
 
Tenser Product of Representation for the Group Cn
Tenser Product of Representation for the Group CnTenser Product of Representation for the Group Cn
Tenser Product of Representation for the Group CnIJERA Editor
 
Research onidentify stadia of interchange exit ramp in mountainous urban freeway
Research onidentify stadia of interchange exit ramp in mountainous urban freewayResearch onidentify stadia of interchange exit ramp in mountainous urban freeway
Research onidentify stadia of interchange exit ramp in mountainous urban freewayIJERA Editor
 
Research on License Plate Recognition and Extraction from complicated Images
Research on License Plate Recognition and Extraction from complicated ImagesResearch on License Plate Recognition and Extraction from complicated Images
Research on License Plate Recognition and Extraction from complicated ImagesIJERA Editor
 
Visual Product Identification for Blind
Visual Product Identification for BlindVisual Product Identification for Blind
Visual Product Identification for BlindIJERA Editor
 
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...IJERA Editor
 
Network Performance Enhancement for 1G-EPON by DBA Algorithms
Network Performance Enhancement for 1G-EPON by DBA AlgorithmsNetwork Performance Enhancement for 1G-EPON by DBA Algorithms
Network Performance Enhancement for 1G-EPON by DBA AlgorithmsIJERA Editor
 
Thermal Simulation of Biogas Plants Using Mat Lab
Thermal Simulation of Biogas Plants Using Mat LabThermal Simulation of Biogas Plants Using Mat Lab
Thermal Simulation of Biogas Plants Using Mat LabIJERA Editor
 
Low Power CMOS Analog Multiplier
Low Power CMOS Analog MultiplierLow Power CMOS Analog Multiplier
Low Power CMOS Analog MultiplierIJERA Editor
 
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...IJERA Editor
 
Design and Fabrication of Eu-Cycle
Design and Fabrication of Eu-CycleDesign and Fabrication of Eu-Cycle
Design and Fabrication of Eu-CycleIJERA Editor
 
Security Issues related with cloud computing
Security Issues related with cloud computingSecurity Issues related with cloud computing
Security Issues related with cloud computingIJERA Editor
 
An Improved Parallel Activity scheduling algorithm for large datasets
An Improved Parallel Activity scheduling algorithm for large datasetsAn Improved Parallel Activity scheduling algorithm for large datasets
An Improved Parallel Activity scheduling algorithm for large datasetsIJERA Editor
 
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...Serviceability behavior of Reinforcement Concrete beams with polypropylene an...
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...IJERA Editor
 
Leveraging the Power of Smartphones: Real Time Monitoring of Water Points
Leveraging the Power of Smartphones: Real Time Monitoring of Water PointsLeveraging the Power of Smartphones: Real Time Monitoring of Water Points
Leveraging the Power of Smartphones: Real Time Monitoring of Water PointsIJERA Editor
 
Transformation of feelings using pitch parameter for Marathi speech
Transformation of feelings using pitch parameter for Marathi speechTransformation of feelings using pitch parameter for Marathi speech
Transformation of feelings using pitch parameter for Marathi speechIJERA Editor
 
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...IJERA Editor
 

Viewers also liked (20)

Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...
Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...
Fluid Structural Modal Coupled Numerical Investigation of Transonic Flutterin...
 
Tenser Product of Representation for the Group Cn
Tenser Product of Representation for the Group CnTenser Product of Representation for the Group Cn
Tenser Product of Representation for the Group Cn
 
Research onidentify stadia of interchange exit ramp in mountainous urban freeway
Research onidentify stadia of interchange exit ramp in mountainous urban freewayResearch onidentify stadia of interchange exit ramp in mountainous urban freeway
Research onidentify stadia of interchange exit ramp in mountainous urban freeway
 
Research on License Plate Recognition and Extraction from complicated Images
Research on License Plate Recognition and Extraction from complicated ImagesResearch on License Plate Recognition and Extraction from complicated Images
Research on License Plate Recognition and Extraction from complicated Images
 
Visual Product Identification for Blind
Visual Product Identification for BlindVisual Product Identification for Blind
Visual Product Identification for Blind
 
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...
Validation of the Newly Developed Fabric Feel Tester for Its Accuracy and Rep...
 
I046044854
I046044854I046044854
I046044854
 
Network Performance Enhancement for 1G-EPON by DBA Algorithms
Network Performance Enhancement for 1G-EPON by DBA AlgorithmsNetwork Performance Enhancement for 1G-EPON by DBA Algorithms
Network Performance Enhancement for 1G-EPON by DBA Algorithms
 
Thermal Simulation of Biogas Plants Using Mat Lab
Thermal Simulation of Biogas Plants Using Mat LabThermal Simulation of Biogas Plants Using Mat Lab
Thermal Simulation of Biogas Plants Using Mat Lab
 
Low Power CMOS Analog Multiplier
Low Power CMOS Analog MultiplierLow Power CMOS Analog Multiplier
Low Power CMOS Analog Multiplier
 
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...
A Mathematical Modeling Approach of the Failure Analysis for the Real-Time Me...
 
Design and Fabrication of Eu-Cycle
Design and Fabrication of Eu-CycleDesign and Fabrication of Eu-Cycle
Design and Fabrication of Eu-Cycle
 
Af044212215
Af044212215Af044212215
Af044212215
 
K046055662
K046055662K046055662
K046055662
 
Security Issues related with cloud computing
Security Issues related with cloud computingSecurity Issues related with cloud computing
Security Issues related with cloud computing
 
An Improved Parallel Activity scheduling algorithm for large datasets
An Improved Parallel Activity scheduling algorithm for large datasetsAn Improved Parallel Activity scheduling algorithm for large datasets
An Improved Parallel Activity scheduling algorithm for large datasets
 
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...Serviceability behavior of Reinforcement Concrete beams with polypropylene an...
Serviceability behavior of Reinforcement Concrete beams with polypropylene an...
 
Leveraging the Power of Smartphones: Real Time Monitoring of Water Points
Leveraging the Power of Smartphones: Real Time Monitoring of Water PointsLeveraging the Power of Smartphones: Real Time Monitoring of Water Points
Leveraging the Power of Smartphones: Real Time Monitoring of Water Points
 
Transformation of feelings using pitch parameter for Marathi speech
Transformation of feelings using pitch parameter for Marathi speechTransformation of feelings using pitch parameter for Marathi speech
Transformation of feelings using pitch parameter for Marathi speech
 
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...
Evaluation of Post-liquefaction Reconsolidation Settlement based on Standard ...
 

Similar to Railway Ticket Counter Problem With STM

Cloud Module 3 .pptx
Cloud Module 3 .pptxCloud Module 3 .pptx
Cloud Module 3 .pptxssuser41d319
 
Turing Lecture - The Computer Science of Concurrency - The Early Years : Notes
Turing Lecture - The Computer Science of Concurrency - The Early Years : NotesTuring Lecture - The Computer Science of Concurrency - The Early Years : Notes
Turing Lecture - The Computer Science of Concurrency - The Early Years : NotesSubhajit Sahu
 
IRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET Journal
 
A Survey on Distributed Transactional Memory System with a Proposed Design fo...
A Survey on Distributed Transactional Memory System with a Proposed Design fo...A Survey on Distributed Transactional Memory System with a Proposed Design fo...
A Survey on Distributed Transactional Memory System with a Proposed Design fo...IRJET Journal
 
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On CloudSecure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On CloudIRJET Journal
 
The Architecture Design for Find Outing Vehicle Position System using Communi...
The Architecture Design for Find Outing Vehicle Position System using Communi...The Architecture Design for Find Outing Vehicle Position System using Communi...
The Architecture Design for Find Outing Vehicle Position System using Communi...Kumar Goud
 
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP IJCSEIT Journal
 
Iaetsd implementation of aho corasick algorithm
Iaetsd implementation of aho corasick algorithmIaetsd implementation of aho corasick algorithm
Iaetsd implementation of aho corasick algorithmIaetsd Iaetsd
 
IRJET- Chatbot Using Gated End-to-End Memory Networks
IRJET-  	  Chatbot Using Gated End-to-End Memory NetworksIRJET-  	  Chatbot Using Gated End-to-End Memory Networks
IRJET- Chatbot Using Gated End-to-End Memory NetworksIRJET Journal
 
Design Package to Build and Evaluate Encryption Algorithms
Design Package to Build and Evaluate Encryption AlgorithmsDesign Package to Build and Evaluate Encryption Algorithms
Design Package to Build and Evaluate Encryption AlgorithmsIOSRjournaljce
 
IRJET- A Survey on Cardless Automated Teller Machine(ATM)
IRJET- A Survey on Cardless Automated Teller Machine(ATM)IRJET- A Survey on Cardless Automated Teller Machine(ATM)
IRJET- A Survey on Cardless Automated Teller Machine(ATM)IRJET Journal
 
Transaction handling in com, ejb and .net
Transaction handling in com, ejb and .netTransaction handling in com, ejb and .net
Transaction handling in com, ejb and .netijseajournal
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhanijyoti_lakhani
 
06 chapter03 04_control_logix_tags_memory_structure_fa16
06 chapter03 04_control_logix_tags_memory_structure_fa1606 chapter03 04_control_logix_tags_memory_structure_fa16
06 chapter03 04_control_logix_tags_memory_structure_fa16John Todora
 
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTING
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTINGDYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTING
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTINGcscpconf
 
Disadvantages Of Robotium
Disadvantages Of RobotiumDisadvantages Of Robotium
Disadvantages Of RobotiumSusan Tullis
 

Similar to Railway Ticket Counter Problem With STM (20)

Cloud Module 3 .pptx
Cloud Module 3 .pptxCloud Module 3 .pptx
Cloud Module 3 .pptx
 
Chap7 slides
Chap7 slidesChap7 slides
Chap7 slides
 
Turing Lecture - The Computer Science of Concurrency - The Early Years : Notes
Turing Lecture - The Computer Science of Concurrency - The Early Years : NotesTuring Lecture - The Computer Science of Concurrency - The Early Years : Notes
Turing Lecture - The Computer Science of Concurrency - The Early Years : Notes
 
IRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable SoftwareIRJET- Development of Uncrackable Software
IRJET- Development of Uncrackable Software
 
A Survey on Distributed Transactional Memory System with a Proposed Design fo...
A Survey on Distributed Transactional Memory System with a Proposed Design fo...A Survey on Distributed Transactional Memory System with a Proposed Design fo...
A Survey on Distributed Transactional Memory System with a Proposed Design fo...
 
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On CloudSecure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
Secure Text Transfer Using Diffie-Hellman Key Exchange Based On Cloud
 
The Architecture Design for Find Outing Vehicle Position System using Communi...
The Architecture Design for Find Outing Vehicle Position System using Communi...The Architecture Design for Find Outing Vehicle Position System using Communi...
The Architecture Design for Find Outing Vehicle Position System using Communi...
 
Co question 2008
Co question 2008Co question 2008
Co question 2008
 
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
Performance Analysis of Parallel Algorithms on Multi-core System using OpenMP
 
Iaetsd implementation of aho corasick algorithm
Iaetsd implementation of aho corasick algorithmIaetsd implementation of aho corasick algorithm
Iaetsd implementation of aho corasick algorithm
 
IRJET- Chatbot Using Gated End-to-End Memory Networks
IRJET-  	  Chatbot Using Gated End-to-End Memory NetworksIRJET-  	  Chatbot Using Gated End-to-End Memory Networks
IRJET- Chatbot Using Gated End-to-End Memory Networks
 
Design Package to Build and Evaluate Encryption Algorithms
Design Package to Build and Evaluate Encryption AlgorithmsDesign Package to Build and Evaluate Encryption Algorithms
Design Package to Build and Evaluate Encryption Algorithms
 
IRJET- A Survey on Cardless Automated Teller Machine(ATM)
IRJET- A Survey on Cardless Automated Teller Machine(ATM)IRJET- A Survey on Cardless Automated Teller Machine(ATM)
IRJET- A Survey on Cardless Automated Teller Machine(ATM)
 
Transaction handling in com, ejb and .net
Transaction handling in com, ejb and .netTransaction handling in com, ejb and .net
Transaction handling in com, ejb and .net
 
unit 2 hpc.pptx
unit 2 hpc.pptxunit 2 hpc.pptx
unit 2 hpc.pptx
 
Ds03 part i algorithms by jyoti lakhani
Ds03 part i algorithms   by jyoti lakhaniDs03 part i algorithms   by jyoti lakhani
Ds03 part i algorithms by jyoti lakhani
 
06 chapter03 04_control_logix_tags_memory_structure_fa16
06 chapter03 04_control_logix_tags_memory_structure_fa1606 chapter03 04_control_logix_tags_memory_structure_fa16
06 chapter03 04_control_logix_tags_memory_structure_fa16
 
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTING
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTINGDYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTING
DYNAMIC TASK PARTITIONING MODEL IN PARALLEL COMPUTING
 
Disadvantages Of Robotium
Disadvantages Of RobotiumDisadvantages Of Robotium
Disadvantages Of Robotium
 
Ig3514391443
Ig3514391443Ig3514391443
Ig3514391443
 

Recently uploaded

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Recently uploaded (20)

OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

Railway Ticket Counter Problem With STM

  • 1. Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 www.ijera.com 13 | P a g e Railway Ticket Counter Problem With STM Mohit Kumar Modi, Utpal Kumar Ray, Ryan Saptarshi Ray, Parama Bhaumik BE(IT) Third year Student Department of Information Technology, Jadavpur University Kolkata, India Associate Professor Department of Information Technology, Jadavpur University ,Kolkata,India Junior Research Fellow 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. RAILWAY TICKET COUNTER PROBLEM In the Railway 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. RAILWAY 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
  • 2. Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 www.ijera.com 14 | P a g e lock-holding thread releases the lock, which it does when it leaves the critical section [2]. In the parallel program using threads and locks which solves the Railway ticket-counter problem the time taken for processing of passenger’s request at each counter(x) and the number of passengers at each counter(y) are taken as input. There is one thread function-“tctr()”. The following code snippet shows the tctr thread: void *tctr(int *num_ptr) { unsigned long j; int num,*number_ptr; number_ptr=num_ptr; num=*number_ptr; pthread_mutex_lock(&mutex1); arr[num]=x*y; if(arr[num]<=proc) { proc= arr[num]; if(x<prev_bestproc) { prev_bestproc=x; } } pthread_mutex_unlock(&mutex1); pthread_exit(0); } In the thread “tctr” the amount of time for which the passenger has to wait to purchase ticket from that counter is calculated by the following code snippet: pthread_mutex_lock(&mutex1); arr[num]=x*y; if(arr[num]<=proc) { proc= arr[num]; if(x<prev_bestproc) { prev_bestproc=x; } } pthread_mutex_unlock(&mutex1); pthread_exit(0); 3 lock calls are being used in the program. pthread_mutex_init(&mutex1,NULL), is used for lock initialization. pthread_mutex_lock(&mutex1), is used for locking. This means that any thread which needs to access the critical section has to first acquire the lock on mutex1. pthread_mutex_unlock(&mutex1), is used for unlocking. In the program the region where more than one thread may access the global array arr at the same time is the critical section. Thus this region is enclosed within locks. Hence there is no synchronization problem in the above code. IV. EXPERIMENTAL RESULTS FOR RAILWAY TICKET-COUNTER PROBLEM USING LOCKS The following table shows the experimental results for Railway ticket-counter problem using locks: NUMBER OF THREADS TIME TAKEN( SEC) SPEEDUP EFFICIENCY 1 12 1 1.00 2 6 2 1.00 3 4 3 1.00 4 3 4 1.00 5 3 4 0.80 6 2 6 1.00 7 2 6 0.86 8 2 6 0.75 9 2 6 0.67 10 2 6 0.60 11 2 6 0.55 12 1 12 1.00 The corresponding graphs for the above experimental results are shown below: From the above graph we can see that as the number of threads increases the time taken decreases.
  • 3. Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 www.ijera.com 15 | P a g e From the above graph we can see that as the number of threads increases the speedup also steadily increases. From the above graph we can see that as the number of threads increases the efficiency varies around 1. V. RAILWAY TICKET-COUNTER PROBLEM USING STM The synchronization problem can also be solved using STM. If STM is used in a program then we do not have to use locks in the program. Thus the problems which occur due to the presence of locks in a program do not occur in this type of code. The critical section of the program has to be enclosed within a transaction. Then STM by its internal constructs ensures synchronization in the program. The structure of the program using threads and STM which solves the railway ticket-counter problem is same as that of the program using threads and locks. The only difference is that STM is being used in this program. The following code snippet shows the tctr thread: void *tctr(int *num_ptr) { unsigned long j; unsigned char byte_under_stm; int num,*number_ptr; number_ptr=num_ptr; num=*number_ptr; stm_init_thread(); START(0,RW); byte_under_stm=(unsigned char) LOAD(&arr[num]); byte_under_stm=x*y; if(byte_under_stm<=proc) { proc= byte_under_stm; if(x<prev_bestproc) prev_bestproc=x; } STORE(&arr[num],byte_under_stm); COMMIT; stm_exit_thread(); pthread_exit(0); } The STM functions and calls which have been used in the code are explained below: stm_init is used to initialize the TinySTM library at the outset. It is called from the main thread before accessing any other functions of the TinySTM library. stm_init_thread is used to initialize each thread that will perform transactions. It is called once from each thread that performs transactional operations before the thread calls any other functions of the TinySTM library. In this program it is called from the thread tctr. stm_exit is the corresponding shutdown function for stm_init. It cleans up the TinySTM library. It is called once from the main thread after all transactional threads have completed execution. stm_exit_thread is the corresponding shutdown function for stm_init_thread. It cleans up the transactional thread. It is called once from each thread that performs transactional operations upon exit. In this program it cleans up the thread tctr. START(0,RW) is used to start a transaction. In this program it is used in the thread tctr. COMMIT is used to close the transaction. In this program it is used in the thread tctr. byte_under_stm=(unsigned char) LOAD(&arr[num]); stores the value of arr[num] in byte_under_stm. In this program it is used in the thread tctr.
  • 4. Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 www.ijera.com 16 | P a g e STORE(&arr[num],byte_under_stm); stores the value of byte_under_stm in arr[num]. In this program it is used in the thread tctr. In this program the region where more than one thread may access the global array arr at the same time is the critical section. Thus this region is enclosed within transaction using TinySTM which is a type of STM. Hence there is no synchronization problem in the above code. VI. EXPERIMENTAL RESULTS FOR RAILWAY TICKET-COUNTER PROBLEM USING STM The following table shows the experimental results for railway ticket-counter problem using STM: NUMBER OF THREADS TIME TAKEN (SEC) SPEEDUP EFFICIENCY 1 12 1 1.00 2 6 2 1.00 3 4 3 1.00 4 3 4 1.00 5 3 4 0.80 6 2 6 1.00 7 2 6 0.86 8 2 6 0.75 9 2 6 0.67 10 2 6 0.60 11 2 6 0.55 12 1 12 1.00 The corresponding graphs for the above experimental results are shown below: From the above graph we can see that as the number of threads increases the time taken decreases. From the above graph we can see that as the number of threads increases the speedup also steadily increases. From the above graph we can see that as the number of threads increases the efficiency varies around 1. VII. PERFORMANCE COMPARISION OF LOCKS AND STM From the above experimental results we see that performance of locks and STM are similar. In the code with locks we have enclosed only the critical section with locks. When we enclosed the entire code with locks then the performance drastically decreased. In the code with STM also we have enclosed only the critical section with STM. When we enclosed the entire code with STM then also the performance remained same. So it can be said that performance of STM is better than that of locks. Also we can say that STM is easier to use than locks as critical section need not be identified in case of STM. VIII. CONCLUSION STM has been shown in many ways to be a good alternative to locks for writing parallel programs. STM provides a time-tested model for isolating concurrent computations from each other. This model raises the level of abstraction for reasoning about
  • 5. Mohit Kumar Modi et al Int. Journal of Engineering Research and Applications www.ijera.com ISSN : 2248-9622, Vol. 4, Issue 7( Version 1), July 2014, pp.13-17 www.ijera.com 17 | P a g e concurrent tasks and helps avoid many parallel programming errors. This paper has discussed how STM can be used to solve the problem of synchronization in parallel programs. STM has ensured that lock-free parallel programs can be written. This ensures that the problems which occur due to the presence of locks in a program do not occur in this type of code. It has also been shown that STM is easier to use than locks as critical section need not be identified explicitly in case of STM. In case of STM if the entire code is enclosed within STM the performance of the code is same as that of the code in which only the critical section is enclosed within STM. But in case of locks if the entire code is enclosed within locks then the performance decreases sharply. So it has been shown that the performance of STM is much better than that of locks. Many aspects of the semantics and implementation of STM are still the subject of active research. While it may still take some time to overcome the various drawbacks, the necessity for better parallel programming solutions will drive the eventual adoption of STM. Once the adoption of STM begins it will pick up momentum and make a very large impact on software development in the long run. In the near future STM will become a central pillar of parallel programming. REFERENCES [1] Simon Peyton Jones, “Beautiful concurrency”. [2] Elan Dubrofsky, “A Survey Paper on Transactional Memory”. [3] Pascal Felber, Christof Fetzer, Torvald Riegel, “Dynamic Performance Tuning of Word-Based Software Transactional Memory”. [4] http://en.wikipedia.org/wiki/Transactional_ memory [5] James Larus and Christos Kozyrakis. “Transactional Memory” [6] Pascal Felber, Christof Fetzer, Patrick Marlier, Torvald Riegel, “Time-Based Software Transactional Memory” [7] Tim Harris, James Larus, Ravi Rajwar, “Transactional Memory” [8] Mathias Payer, Thomas R. Gross, “Performance Evaluation of Adaptivity in Software Transactional Memory” [9] Kevin E. Moore, Jayaram Bobba, Michelle J. Moravan, Mark D. Hill, David A. Wood., “LogTM: Log-based Transactional Memory” [10] Dave Dice , Ori Shalev , Nir Shavit., “Transactional Locking II” [11] http://tmware.org [12] Maurice Herlihy, J. Eliot B. Moss, “Transactional Memory: Architectural Support for Lock-Free Data Structures”. [13] Martin Schindewolf, Albert Cohen, Wolfgang Karl, Andrea Marongiu, Luca Benini, “Towards Transactional Memory Support for GCC”. [14] Virendra J. Marathe, Michael F. Spear, Christopher Heriot, Athul Acharya, David Eisenstat, William N. Scherer III, Michael L. Scott, “Lowering the Overhead of Nonblocking Software Transactional Memory”. [15] Utku Aydonat, Tarek S. Abdelrahman, Edward S. Rogers Sr., “Serializability of Transactions in Software Transactional Memory”. [16] Maurice Herlihy, Nir Shavit, “The Art of Multiprocessor Programming”. [17] Brendan Linn, Chanseok Oh, “G22.2631 project report: software transactional memory”. [18] http://en.wikipedia.org/wiki/Software_transactional_memory [19] http://research.microsoft.com/~simonpj/papers/stm/ [20] http://www.haskell.org/haskellwiki/Software_transactional_memory. [21] Ryan Saptarshi Ray, “Writing Lock-Free Code using Software Transactional Memory ”. [22] Ryan Saptarshi Ray,Utpal Kumar Ray “Different Approaches for improving performance of Software Transactional Memory ”.