Thread

Name

Thread -- Abstract base class for thread objects.

Synopsis


#include <Thread.h>
         
 class Thread {

  Thread()();
  Thread(std::string name);

  virtual ~Thread();

  int detach();
  unsigned long getId();
  void start();
  void setName(std::string name);
  void join();
  const std::string getName();
  virtual = 0 void run();
}

Description

Thread is an abstract base class that can be used to create threads. To make a thread you will normally derive a class from Thread and write the run method to implement the thread's code.

A thread can then be created like any other object. The start method schedules the thread's run member for execution

Threads can block on the completion of a thread via the join method.

Public member functions

Constructors. Constructors create a thread. The thread is not scheduled for execution until the start method is called. Threads can have an optional thread name.

Thread()();

Constructs an anonymous thread.

Thread(std::string name);

Constructs a named thread.

Thread identification. Threads are identified by an optional name, which need not be unique, and a unique identifier (thread id), that is assigned by the underlying operating systemn.

unsigned long getId();

Returns the thread id. If the thread has not yet been started, -1 is returned regardless of the thread. A thread only gets an id when it has been started.

void start();

Starts a thread. A thread id is allocated and the run method is scheduled for execution.

void setName(std::string name);

Modifies the name of the thread.

int detach();

Detaches an executing thread. If the thread has not started, this returns -1. Detaching a thread indicates that any operating system storage (not object storage) associated with a thread can be released when the thread exits. If the thread does not detach, it is necessary to join the thread to fully release its storage.

On success, 0 should be returned, otherwise a value that is one of the values in errno.h is returned to describe why the call failed.

void join();

join blocks until the thread exits. When the thread does exit, thread specific storage is reclaimed. Note that if a thread has calledis detach it is not clear clear wht clear what this member will do.

const std::string getName(); virtual = 0 void run();

You must implement this function to provide a concrete Thread run-time behavior.