Skip to topic | Skip to bottom
Home
DGD

Welcome Register

TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs DGD Main Sandbox TWiki Welcome Register


TWiki Web TWiki Web Home Changes Topics Index Search


TWiki Webs DGD Main Sandbox TWiki Create personal sidebar porn free porn

DGD.ThreadLocalStorager1.1 - 20 Jan 2005 - 22:28 - ErwinHartetopic end

Start of topic | Skip to actions

Thread Local Storage

Thread Local Storage (TLS) is a method of storing information specific (and probably global) to a specific thread. Although not essential at the moment, it will be important for DGD-MP (multi-processor) as the alternatives will prevent multiple threads to run at once.

The important KernelLib class here is /kernel/lib/api/tls. In order to use it, inherit it into whatever object you wish to add use it. You will need to backcall tls' create() function. This will give you access to the following functions:

get_tlvar

Description
mixed get_tlvar(int index)

Requires
0 <= index

Returns
Whatever has been stored in that index of the Thread Local Storage.

set_tlvar

Description
void set_tlvar(int index, mixed value)

Requires
0 <= index

Function
Stores the value in the appropriate index of Thread Local Storage.

set_tls_size

Description
void set_tls_size(int size)

Requires
0 <= size

Function
Sets the size of Thread Local Storage.

Example

An example of how you would use TLS to implement this_player() in an auto object.

private inherit tls "/kernel/lib/api/tls";

static void create() {
    tls::create();
    set_tls_size(1); /* one thread local variable, index 0 */
}

static void set_this_player(object player) {
    set_tlvar(0, player);
}

/* return the current player */
static object this_player() {
    return get_tlvar(0);
}

-- ErwinHarte - 20 Jan 2005
to top


You are here: DGD > ThreadLocalStorage

to top

Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback