gthread.Cond.Cond 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

GCondgetCondStruct ()
 this (GCond *gCond)
 Sets our main struct and passes it to the parent class.
 this ()
 Creates a new GCond.
void signal ()
 If threads are waiting for cond, exactly one of them is woken up.
void broadcast ()
 If threads are waiting for cond, all of them are woken up.
void wait (Mutex mutex)
 Waits until this thread is woken up on cond.
int timedWait (Mutex mutex, GTimeVal *absTime)
 Waits until this thread is woken up on cond, but not longer than until the time specified by abs_time.
void free ()
 Destroys the GCond.

Protected Member Functions

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

Protected Attributes

GCondgCond
 the main Gtk struct


Constructor & Destructor Documentation

gthread.Cond.Cond.this ( GCond gCond  ) 

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

gthread.Cond.Cond.this (  ) 

Creates a new GCond.

This function will abort, if g_thread_init() has not been called yet. Returns: a new GCond.


Member Function Documentation

void gthread.Cond.Cond.broadcast (  ) 

If threads are waiting for cond, all of them are woken up.

It is good practice to lock the same mutex as the waiting threads, while calling this function, though not required. This function can be used even if g_thread_init() has not yet been called, and, in that case, will do nothing. cond: a GCond.

void gthread.Cond.Cond.free (  ) 

Destroys the GCond.

cond: a GCond.

GCond* gthread.Cond.Cond.getCondStruct (  ) 

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

the main Gtk struct as a void*

void gthread.Cond.Cond.signal (  ) 

If threads are waiting for cond, exactly one of them is woken up.

It is good practice to hold the same lock as the waiting thread while calling this function, though not required. This function can be used even if g_thread_init() has not yet been called, and, in that case, will do nothing. cond: a GCond.

int gthread.Cond.Cond.timedWait ( Mutex  mutex,
GTimeVal absTime 
)

Waits until this thread is woken up on cond, but not longer than until the time specified by abs_time.

The mutex is unlocked before falling asleep and locked again before resuming. If abs_time is NULL, g_cond_timed_wait() acts like g_cond_wait(). This function can be used even if g_thread_init() has not yet been called, and, in that case, will immediately return TRUE. To easily calculate abs_time a combination of g_get_current_time() and g_time_val_add() can be used. cond: a GCond. mutex: a GMutex that is currently locked. abs_time: a GTimeVal, determining the final time. Returns: TRUE if cond was signalled, or FALSE on timeout.

void gthread.Cond.Cond.wait ( Mutex  mutex  ) 

Waits until this thread is woken up on cond.

The mutex is unlocked before falling asleep and locked again before resuming. This function can be used even if g_thread_init() has not yet been called, and, in that case, will immediately return. cond: a GCond. mutex: a GMutex, that is currently locked.


Member Data Documentation

GCond* gthread.Cond.Cond.gCond [protected]

the main Gtk struct


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