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

GStaticRecMutexgetStaticRecMutexStruct ()
 this (GStaticRecMutex *gStaticRecMutex)
 Sets our main struct and passes it to the parent class.
void init ()
 A GStaticRecMutex must be initialized with this function before it can be used.
void lock ()
 Locks mutex.
int trylock ()
 Tries to lock mutex.
void unlock ()
 Unlocks mutex.
void lockFull (uint depth)
 Works like calling g_static_rec_mutex_lock() for mutex depth times.
uint unlockFull ()
 Completely unlocks mutex.
void free ()
 Releases all resources allocated to a GStaticRecMutex.

Protected Member Functions

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

Protected Attributes

GStaticRecMutexgStaticRecMutex
 the main Gtk struct


Constructor & Destructor Documentation

gthread.StaticRecMutex.StaticRecMutex.this ( GStaticRecMutex gStaticRecMutex  ) 

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


Member Function Documentation

void gthread.StaticRecMutex.StaticRecMutex.free (  ) 

Releases all resources allocated to a GStaticRecMutex.

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

GStaticRecMutex* gthread.StaticRecMutex.StaticRecMutex.getStaticRecMutexStruct (  ) 

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

the main Gtk struct as a void*

void gthread.StaticRecMutex.StaticRecMutex.init (  ) 

A GStaticRecMutex must be initialized with this function before it can be used.

Alternatively you can initialize it with G_STATIC_REC_MUTEX_INIT. mutex: a GStaticRecMutex to be initialized.

void gthread.StaticRecMutex.StaticRecMutex.lock (  ) 

Locks mutex.

If mutex is already locked by another thread, the current thread will block until mutex is unlocked by the other thread. If mutex is already locked by the calling thread, this functions increases the depth of mutex and returns immediately. mutex: a GStaticRecMutex to lock.

void gthread.StaticRecMutex.StaticRecMutex.lockFull ( uint  depth  ) 

Works like calling g_static_rec_mutex_lock() for mutex depth times.

mutex: a GStaticRecMutex to lock. depth: number of times this mutex has to be unlocked to be completely unlocked.

int gthread.StaticRecMutex.StaticRecMutex.trylock (  ) 

Tries to lock mutex.

If mutex is already locked by another thread, it immediately returns FALSE. Otherwise it locks mutex and returns TRUE. If mutex is already locked by the calling thread, this functions increases the depth of mutex and immediately returns TRUE. mutex: a GStaticRecMutex to lock. Returns: TRUE, if mutex could be locked.

void gthread.StaticRecMutex.StaticRecMutex.unlock (  ) 

Unlocks mutex.

Another thread can will be allowed to lock mutex only when it has been unlocked as many times as it had been locked before. If mutex is completely unlocked and another thread is blocked in a g_static_rec_mutex_lock() call for mutex, it will be woken and can lock mutex itself. mutex: a GStaticRecMutex to unlock.

uint gthread.StaticRecMutex.StaticRecMutex.unlockFull (  ) 

Completely unlocks mutex.

If another thread is blocked in a g_static_rec_mutex_lock() call for mutex, it will be woken and can lock mutex itself. This function returns the number of times that mutex has been locked by the current thread. To restore the state before the call to g_static_rec_mutex_unlock_full() you can call g_static_rec_mutex_lock_full() with the depth returned by this function. mutex: a GStaticRecMutex to completely unlock. Returns: number of times mutex has been locked by the current thread.


Member Data Documentation

GStaticRecMutex* gthread.StaticRecMutex.StaticRecMutex.gStaticRecMutex [protected]

the main Gtk struct


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