Threads in NMM

Motama GmbH, Saarbruecken, Germany

http://www.motama.com

April 2007

  Copyright (C) 2007,
  Motama GmbH, Saarbruecken, Germany
  http://www.motama.com
 
  Permission is granted to copy, distribute and/or modify this
  document under the terms of the GNU Free Documentation License,
  Version 1.2 or any later version published by the Free Software
  Foundation; with the Invariant Sections being all sections, no
  Front-Cover Texts, and no Back-Cover Texts. A copy of the license
  can be found in the file COPYING.FDL.

  THE DOCUMENT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
  NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE
  DISTRIBUTING THE DOCUMENT BE LIABLE FOR ANY DAMAGES OR OTHER
  LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
  OF OR IN CONNECTION WITH THE DOCUMENT OR THE USE OR OTHER DEALINGS
  IN THE DOCUMENT.


Table of Contents
1. Class Thread
2. Class ThreadMutex
3. Class ThreadCondition
4. Class MutexGuard

1. Class Thread

This Class Thread is a wrapper for the correspond platform dependent threading library. The start-method creates a new thread of control that executes concurrently with the calling thread. The methods and the arguments are similar to the corresponding low-level methods. The following example shows how to create a new Thread.

void* thread_method(void* argument) {
  ....
  return 0;
}

class Foo::foo() {
  Thread new_thread;
  new_thread.start(thread_method,0); //runs the method thread_method in a new thread,
                                     //with no arguments.
  ...

  new_thread.join()                  // blocks until the thread terminates
}