gthread.StaticPrivate.StaticPrivate Class Reference

List of all members.

Detailed Description

Description Threads act almost like processes, but unlike processes all threads of one process share the same memory.

This is good, as it provides easy communication between the involved threads via this shared memory, and it is bad, because strange things (so called "Heisenbugs") might happen if the program is not carefully designed. In particular, due to the concurrent nature of threads, no assumptions on the order of execution of code running in different threads can be made, unless order is explicitly forced by the programmer through synchronization primitives. The aim of the thread related functions in GLib is to provide a portable means for writing multi-threaded software. There are primitives for mutexes to protect the access to portions of memory (GMutex, GStaticMutex, G_LOCK_DEFINE, GStaticRecMutex and GStaticRWLock). There are primitives for condition variables to allow synchronization of threads (GCond). There are primitives for thread-private data - data that every thread has a private instance of (GPrivate, GStaticPrivate). Last but definitely not least there are primitives to portably create and manage threads (GThread). You must call g_thread_init() before executing any other GLib functions in a threaded GLib program. After that, GLib is completely thread safe (all global data is automatically locked), but individual data structure instances are not automatically locked for performance reasons. So, for example you must coordinate accesses to the same GHashTable from multiple threads. The two notable exceptions from this rule are GMainLoop and GAsyncQueue, which are threadsafe and needs no further application-level locking to be accessed from multiple threads.


Public Member Functions

GStaticPrivategetStaticPrivateStruct ()
 this (GStaticPrivate *gStaticPrivate)
 Sets our main struct and passes it to the parent class.
void init ()
 Initializes private_key.
void * get ()
 Works like g_private_get() only for a GStaticPrivate.
void set (void *data, GDestroyNotify notify)
 Sets the pointer keyed to private_key for the current thread and the function notify to be called with that pointer (NULL or non-NULL), whenever the pointer is set again or whenever the current thread ends.
void free ()
 Releases all resources allocated to private_key.

Protected Member Functions

void * getStruct ()
 the main Gtk struct as a void*

Protected Attributes

GStaticPrivategStaticPrivate
 the main Gtk struct


Constructor & Destructor Documentation

gthread.StaticPrivate.StaticPrivate.this ( GStaticPrivate gStaticPrivate  ) 

Sets our main struct and passes it to the parent class.


Member Function Documentation

void gthread.StaticPrivate.StaticPrivate.free (  ) 

Releases all resources allocated to private_key.

You don't have to call this functions for a GStaticPrivate with an unbounded lifetime, i.e. objects declared 'static', but if you have a GStaticPrivate as a member of a structure and the structure is freed, you should also free the GStaticPrivate. private_key: a GStaticPrivate to be freed.

void* gthread.StaticPrivate.StaticPrivate.get (  ) 

Works like g_private_get() only for a GStaticPrivate.

This function works even if g_thread_init() has not yet been called. private_key: a GStaticPrivate. Returns: the corresponding pointer.

GStaticPrivate* gthread.StaticPrivate.StaticPrivate.getStaticPrivateStruct (  ) 

void* gthread.StaticPrivate.StaticPrivate.getStruct (  )  [protected]

the main Gtk struct as a void*

void gthread.StaticPrivate.StaticPrivate.init (  ) 

Initializes private_key.

Alternatively you can initialize it with G_STATIC_PRIVATE_INIT. private_key: a GStaticPrivate to be initialized.

void gthread.StaticPrivate.StaticPrivate.set ( void *  data,
GDestroyNotify  notify 
)

Sets the pointer keyed to private_key for the current thread and the function notify to be called with that pointer (NULL or non-NULL), whenever the pointer is set again or whenever the current thread ends.

This function works even if g_thread_init() has not yet been called. If g_thread_init() is called later, the data keyed to private_key will be inherited only by the main thread, i.e. the one that called g_thread_init(). Note notify is used quite differently from destructor in g_private_new(). private_key: a GStaticPrivate. data: the new pointer. notify: a function to be called with the pointer whenever the current thread ends or sets this pointer again.


Member Data Documentation

GStaticPrivate* gthread.StaticPrivate.StaticPrivate.gStaticPrivate [protected]

the main Gtk struct


SourceForge.net Logo DSource.org Logo digitalmars.com Logo