Reference Manual

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Inti::G::Private< T > Class Template Reference

A run-time GStaticPrivate C++ wrapper interface. More...

`#include <inti/glib/thread.h>`

Inheritance diagram for Inti::G::Private< T >:

List of all members.

## Public Member Functions

Constructors

- Private ()
    Constructs and initializes a new private key.
- ~Private ()
    Destructor. Frees the private key.

## Detailed Description

### template<typename T>
class Inti::G::Private< T >

A run-time GStaticPrivate C++ wrapper interface.

The Private object represents a thread private data key. Threads can thereby obtain and set a pointer, which is private to the current thread. Take our give_me_next_number() example from previously. Now we don't want current_number to be shared between the threads, but to be private to each thread. This can be done as follows:

Example: Using G::Private for per-thread data.

        G::Private<int> *current_number_key = 0; // Must be initialized somewhere.

        int give_me_next_number()
        {
            int *current_number = current_number_key->get();

            if (!current_number)
            {
                    current_number = new int;
                    *current_number = 0;
                    current_number_key->set(current_number);
            }
            *current_number = calc_next_number(*current_number);
            return *current_number;
        }

Here the pointer belonging to the key current_number_key is read. If it is null, it has not been set yet. Then get memory for an integer value, assign this memory to the pointer and write the pointer back. Now we have an integer value, that is private to the current thread.

The documentation for this class was generated from the following file:

- thread.h

Main Page - Footer