by George Walsh, freelance researcher and writer. Intel Corp.
The different means of building multithreaded applications have been a source of some debate. Some developers think the traditional method—using locks—is best, while others are proponents of avoiding the use of locks entirely. Though the different camps each have their points, here are the basics of the different methods, along with an attempt to outline their respective pros and cons.
Multithreaded programming, until recently, provided the greatest benefits to those building applications in the world of servers, where execution on multiple processors with access to shared memory was the norm. While programmers of server applications are still building programs that distribute the processing burden across more than one processor, the advent of the Intel® Pentium® 4 with Hyper-Threading Technology (HTT) has brought multithreading to the desktop. HTT makes a single physical processor function as two logical processors, allowing developers of desktop software to take advantage of the virtues of multiprocessing. Whether you're building server applications or discovering the advantage of desktop multithreading, you'll find—as in all types of programming—different schools of thought on how to best reap the benefits of distributing and synchronizing threads while avoiding such pitfalls as deadlock. Here, we'll try to make some sense of the design of multithreading systems.
Synchronization: The Key to Multitasking Benefits
Threading is nothing new to most programmers. Even those targeting single-processor, non-HTT environments may use threads as a matter of convenience in programming and debugging. Sometimes, separate threads are spawned off to handle specific tasks. However, on multiprocessor or HTT systems, programs can be designed to run optimally by performing a number of tasks simultaneously. To take advantage of this capability, the threads must be synchronized appropriately to do what they need to do at the right time.
In order to avoid race conditions during the execution of a threaded application, mutual exclusion to shared resources is required to allow a single thread to access and change the state of shared resources. The shared resource can be a data structure or variable in the address space. Minimizing synchronization overheads is critical to application performance. In multithreaded applications, while a thread is executing a code section that accesses a shared resource (critical region), other threads waiting to access that resource are either spinning or waiting in a queue.
Typically, synchronization duties are handled by making use of locks (semaphores being a generalized form) which are a means of limiting or controlling access to a resource when many threads are executing. Locks can be implemented in many ways and are the more traditional means of handling synchronization between threads. In addition to conventional multithreading methodologies, some developers also vehemently believe that there can be performance benefits gained by developing multithreaded applications that either don't use locks or use them very sparingly
![]()
![]() | Branch and loop reorganization to prevent misdirects by Jeff Andrews, application engineer, Intel Corp. Proven technique... |
If you're interested in this topic, these articles may be helpful:
![]() | CMP Implementation in Systems Based on the Intel® Core™ Duo processor The Intel Core™ Duo processor is the first mobile processor to i... |
![]() | Deadlock Analysis using DevPartner Studio Multi-threaded applications open the door to difficult-to-diagnose thr... |
![]() | Multithreaded technology and multi-core processors by Craig Szydlowski, Infrastructure Processor Division, Intel Corp. ... |
![]() | Developing Multithreaded Applications: A Platform Consistent Approach Multithreading Consistency Guide The objective of the Multithreading ... |
![]() | Nuts and Bolts of Multithreaded Programming By Tim Mattson Get the basics about parallel algorithms, parallel p... |
![]()
Related Jobs:


