D Programming Language 2.0

- Comments
- D
- Search
- Home

Last update Wed Jun 18 00:14:37 2008

# std.thread

The thread module defines the class Thread.
Thread is the basis for writing multithreaded applications. Each thread has a unique instance of class Thread associated with it. It is important to use the Thread class to create and manage threads as the garbage collector needs to know about all the threads.

alias thread_hdl;
  The type of the thread handle used by the operating system. For Windows, it is equivalent to a HANDLE from windows.d.
class ThreadError: object.Error;
  Thrown for errors.
class Thread;
  One of these is created for each thread.
  this(size_t stacksize = 0);
    Constructor used by classes derived from Thread that override main(). The optional stacksize parameter default value of 0 will cause threads to be created with the default size for the executable - Dave Fladebo
  this(int function(void*) fp, void* arg, size_t stacksize = 0);
    Constructor used by classes derived from Thread that override run().
  this(int delegate() dg, size_t stacksize = 0);
    Constructor used by classes derived from Thread that override run().
  thread_hdl hdl;
    The handle to this thread assigned by the operating system. This is set to thread_id.init if the thread hasn't been started yet.
  void start();
    Create a new thread and start it running. The new thread initializes itself and then calls run(). start() can only be called once.
  int run();
    Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg.
    Returns:
    the thread exit code, which is normally 0.
  void wait();
    Wait for this thread to terminate. Simply returns if thread has already terminated.
    Throws:
    ThreadError if the thread hasn't begun yet or is called on itself.
  void wait(uint milliseconds);
    Wait for this thread to terminate or until milliseconds time has elapsed, whichever occurs first. Simply returns if thread has already terminated.
    Throws:
    ThreadError if the thread hasn't begun yet or is called on itself.
  enum TS;
    The state of a thread.
    INITIAL
      The thread hasn't been started yet.
    RUNNING
      The thread is running or paused.
    TERMINATED
      The thread has ended.
    FINISHED
      The thread has been cleaned up
  TS getState();
    Returns the state of a thread.
  enum PRIORITY;
    The priority of a thread.
    INCREASE
      Increase thread priority
    DECREASE
      Decrease thread priority
    IDLE
      Assign thread low priority
    CRITICAL
      Assign thread high priority
  void setPriority(PRIORITY p);
    Adjust the priority of this thread.
    Throws:
    ThreadError if cannot set priority
  bool isSelf();
    Returns true if this thread is the current thread.
  static Thread getThis();
    Returns a reference to the Thread for the thread that called the function.
  static Thread[] getAll();
    Returns an array of all the threads currently running.
  void pause();
    Suspend execution of this thread.
  void resume();
    Resume execution of this thread.
  static void pauseAll();
    Suspend execution of all threads but this thread.
  static void resumeAll();
    Resume execution of all paused threads.
  static void yield();
    Give up the remainder of this thread's time slice.
  static uint nthreads;
  static void thread_init();
    Create a Thread for global main().
void* os_query_stackBottom();
  Determine "bottom" of stack (actually the top on Win32 systems).

Copyright © 1999-2008 by Digital Mars, All Rights Reserved | Page generated by Ddoc.