LINUX TIPS AND TRICKS --- June 29, 2001

Published by ITworld.com -- changing the way you view IT
http://www.itworld.com/newsletters
________________________________________________________________

Concurrency Concepts
By Danny Kalev

As we already know, Linux supports two forms of concurrency ? 
multiprocessing and multithreading. Multiprocessing means that 
the system can execute two or more processes (either distinct 
ones or multiple instances of the same program) simultaneously. 
Multithreading means that the same process may have two or more 
distinct, concurrently executing code segments, or threads, 
that share some or all of its resources. Each of these two 
forms mandates different synchronization and mutual exclusion 
features to ensure data consistency and avoid race conditions.

Events are a common concept in multithreaded environments. A 
thread may depend on various event types: setting a flag, 
releasing a lock, receiving a signal and so on. When a thread 
is waiting for an event, the scheduler blocks it and removes 
it from the run queue until the event occurs.

In a multithreaded environment, every thread may be 
interrupted, or preempted, at any given time. In fact, it may 
be interrupted between every two CPU instructions. Certain 
operations, however, must be completed without interruption. 
Such operations are said to be atomic. A database transaction 
is a good example of this. Likewise, the process of inserting a 
new task to the kernel's active task list is atomic. A thread 
that performs an atomic operation has non-interruptible access 
to the system's CPU. On multiprocessor machines, spinlocks 
(which we discussed several weeks ago) lock a certain processor 
for a task that is waiting for a lock.

Linux supports the following synchronization mechanisms:

    * Critical Section
      A critical section is a piece of code that may be
      accessed only by a single thread at a time, for example a
      code segment that changes a shared variable.

    * Mutual Exclusion
      A mutual exclusion (mutex for short) is an object that
      restricts access to a variable or code section to a single
      thread at a time. Thus, you may use a mutex to protect a
      critical code section.

    * Semaphores
      A semaphore restricts access to a variable or object to a
      limited number of threads. For example, a semaphore may
      be used to ensure that three threads at most access a
      system's clock.

About the author(s)
-------------------
Danny Kalev is a system analyst and software engineer with 
more than 10 years of experience, specializing in C++ and 
object-oriented analysis and design on various platforms 
including VMS, DOS, Windows, Unix, and Linux. His technical 
interests involve code optimization, networking, and 
distributed computing. He is also a member of the ANSI C++ 
standardization committee and the author of ANSI/ISO C++ 
Professional Programmer's Handbook (Que, 1999). Contact him at 
linuxnl@excite.com.
________________________________________________________________

CUSTOMER SERVICE

SUBSCRIBE/UNSUBSCRIBE:
- Go to: http://reg.itworld.com/cgi-bin/subcontent12.cgi
- Enter your email address under "Current subscriber" to log in
- Uncheck the box next to the newsletter you want to
  unsubscribe from
- Or check the box next to the newsletter you want to
  subscribe to
- Submit

If you have questions, please send email to customer service at:
mailto:support@itworld.com
________________________________________________________________

CONTACTS

* For editorial comments, write Andrew Santosusso, Associate
  Editor, Newsletters at: andrew_santosusso@itworld.com

* For advertising information, write Dan Chupka, Account
  Executive at:  dan_chupka@itworld.com

* For recruitment advertising information, write Jamie Swartz,
  Eastern Regional Sales Manager at: jamie_swartz@itworld.com
  or Paul Duthie,  Western Regional Sales Manager at:
  paul_duthie@itworld.com

* For all other inquiries, write Jodie Naze, Product Manager, 
  Newsletters at: jodie_naze@itworld.com
________________________________________________________________

PRIVACY POLICY
http://www.itworld.com/Privacy/

Copyright 2001 ITworld.com, Inc., All Rights Reserved.
http://www.itworld.com
