|
|
Intel BlogsWhitepapers
|
Multiple approaches to multithreaded applicationsMultithreaded Applications: Multithreaded programming is coming more to the fore with the Intel Pentium 4's support of Hyper-Threading Technology. The approach you choose for thread synchronization--using locks or lock-free--depends on the type of application you're building. More on software multithreading and multithreaded programming
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 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
Subscribers who liked this article also read:
If you're interested in this topic, these articles may be helpful:
Related Jobs: |
|
|