General Info

Interface: Thread
Files: lib/thread.h
Last change: 10/02/2002
Author: Luiz Henrique Shigunov
Description
Functions
  • 0x03 - AllocTSD - Alloc a TSD
  • 0x00 - Create - Create a thread
  • 0x01 - Destroy - Destroy a thread
  • 0x04 - FreeTSD - Free a TSD
  • 0x02 - GetID - Get thread ID
  • 0x05 - GetTSD - Get a TSD value
  • 0x06 - SetTSD - Set a TSD value
  • Description

    This page describes Thread user interface.

    Every program that uses more than one thread must use this interface to create and destroy them.

    Programs often need global or static variables that have different values in different threads. Since threads share one memory space, this cannot be achieved with regular variables. Thread-specific data (TSD) is the answer to this need.

    Each thread possesses a private memory block, the thread-specific data area, or TSD area for short. This area is indexed by TSD keys. The TSD area associates values of type void * to TSD keys. TSD keys are common to all threads, but the value associated with a given TSD key can be different in each thread.

    When a thread is created, its TSD area initially associates NULL with all keys.

    0x03 - AllocTSD

    Syntax

    int AllocTSD(unsigned int *key, void (*destructor)(void*));

    Description

    This function allocates a TSD key.

    There is a limit on the number of keys available. The value initially associated with the returned key is NULL in all threads.

    destructor is still no used.

    If all goes ok, key will have the TSD key.

    Return value

    0x00 - Create

    Syntax

    int Create(int (*function)(void*), void *arg, int prop, Thread **id);

    Description

    This function creates a thread with properties prop.

    The thread will start to execute function with argument arg.

    prop must be 0 or the sum of:

    If all goes ok, id will have the thread id.

    Return value

    0x01 - Destroy

    Syntax

    int Destroy(Thread *id);

    Description

    This function destroys thread id.

    If id is NULL, current thread is destroyed.

    Return value

    0x04 - FreeTSD

    Syntax

    int FreeTSD(unsigned int key);

    Description

    This function frees the TSD key.

    Return value

    0x02 - GetID

    Syntax

    Thread *GetID(void);

    Description

    This function gets the thread ID of the caller.

    Return value

    The thread ID

    0x05 - GetTSD

    Syntax

    void *GetTSD(unsigned int key);

    Description

    This function gets the value of the TSD key in the calling thread.

    Return value

    The value of the TSD key.

    0x06 - SetTSD

    Syntax

    int SetTSD(unsigned int key, void *value);

    Description

    This function sets the value of the TSD key to value in the calling thread.

    Return value