Click here to Skip to main content
15,893,663 members
Articles / Desktop Programming / MFC

Genetic Algorithm Library

Rate me:
Please Sign up or sign in to vote.
4.93/5 (175 votes)
7 Apr 2012GPL358 min read 439.4K   34.7K   555  
A framework for genetic algorithms
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Genetic Algorithm Library: source/Threading.h File Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.5 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div>
<div class="contents">
<h1>source/Threading.h File Reference</h1>This file contains declaration of classes and types used to abstract operating system specific threads control. <a href="#_details">More...</a>
<p>
<code>#include &quot;<a class="el" href="_platform_8h.html">Platform.h</a>&quot;</code><br>
<code>#include &lt;windows.h&gt;</code><br>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Namespaces</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">namespace &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html">Threading</a></td></tr>

<tr><td colspan="2"><br><h2>Classes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_threading_1_1_ga_thread_parameter.html">Threading::GaThreadParameter</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code><a class="el" href="struct_threading_1_1_ga_thread_parameter.html" title="GaThreadParameter structure contains information needed to start new thread. It has...">GaThreadParameter</a></code> structure contains information needed to start new thread. It has pointer to function which is entry point of thread and pointer to parameters which will be passed to the function. Restrictions of entry point's function of a thread are described by <code>GaThreadFunctionPointer</code> type.  <a href="struct_threading_1_1_ga_thread_parameter.html#_details">More...</a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">class &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_threading_1_1_ga_critical_section.html">Threading::GaCriticalSection</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code><a class="el" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">GaCriticalSection</a></code> class is wrapper class for system synchronization object.  <a href="class_threading_1_1_ga_critical_section.html#_details">More...</a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">class &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_threading_1_1_ga_section_lock.html">Threading::GaSectionLock</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code><a class="el" href="class_threading_1_1_ga_section_lock.html" title="GaSectionLock class is used for automatic access control with help of GaCriticalSection...">GaSectionLock</a></code> class is used for automatic access control with help of <a class="el" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">GaCriticalSection</a> class. Synchronization object can be automatically acquired when instance of <code><a class="el" href="class_threading_1_1_ga_section_lock.html" title="GaSectionLock class is used for automatic access control with help of GaCriticalSection...">GaSectionLock</a></code> is created. If synchronization object is locked by instance of <code><a class="el" href="class_threading_1_1_ga_section_lock.html" title="GaSectionLock class is used for automatic access control with help of GaCriticalSection...">GaSectionLock</a></code> it is released when the instance goes out of scope. This mechanism provides simple way of managing critical sections because users don't have to worry about releasing of synchronization object in most cases, but for more complicated cases <code>LOCK</code> and <code>UNLOCK</code> macros can be used with instances of this class or with <a class="el" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">GaCriticalSection</a> class. <code><a class="el" href="class_threading_1_1_ga_section_lock.html" title="GaSectionLock class is used for automatic access control with help of GaCriticalSection...">GaSectionLock</a></code> is mainly employed by <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code>.  <a href="class_threading_1_1_ga_section_lock.html#_details">More...</a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">class &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_threading_1_1_ga_thread.html">Threading::GaThread</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code><a class="el" href="class_threading_1_1_ga_thread.html" title="GaThread class controls system threads. It wraps system specific control of threading...">GaThread</a></code> class controls system threads. It wraps system specific control of threading. This class has built-in synchronizator so it is allowed to use <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros with instances of this class.  <a href="class_threading_1_1_ga_thread.html#_details">More...</a><br></td></tr>
<tr><td colspan="2"><br><h2>Defines</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#a85596536fefa7f93352463a0a79a2fd">ATOMIC_INC</a>(VALUE)&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>ATOMIC_INC</code> macro atomically increments <code>VALUE</code> by one and returns new value.  <a href="#a85596536fefa7f93352463a0a79a2fd"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#dbe76a6042d420484798146558d9f374">ATOMIC_DEC</a>(VALUE)&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>ATOMIC_DEC</code> macro atomically decrements <code>VALUE</code> by one and returns new value.  <a href="#dbe76a6042d420484798146558d9f374"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#8a27192e44aff715076b494e2a0a2872">SPINLOCK</a>(LOCK)&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>SPINLOCK</code> macro defines mechanism of spinlock.  <a href="#8a27192e44aff715076b494e2a0a2872"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#a85596536fefa7f93352463a0a79a2fd">ATOMIC_INC</a>(VALUE)&nbsp;&nbsp;&nbsp;InterlockedIncrement( (LONG*)&amp;VALUE )</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>ATOMIC_INC</code> macro atomically increments <code>VALUE</code> by one and returns new value.  <a href="#a85596536fefa7f93352463a0a79a2fd"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#dbe76a6042d420484798146558d9f374">ATOMIC_DEC</a>(VALUE)&nbsp;&nbsp;&nbsp;InterlockedDecrement( (LONG*)&amp;VALUE )</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>ATOMIC_DEC</code> macro atomically decrements <code>VALUE</code> by one and returns new value.  <a href="#dbe76a6042d420484798146558d9f374"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#8a27192e44aff715076b494e2a0a2872">SPINLOCK</a>(LOCK)&nbsp;&nbsp;&nbsp;while( InterlockedExchange( (LONG*)&amp;LOCK, 1 ) )</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>SPINLOCK</code> macro defines mechanism of spinlock.  <a href="#8a27192e44aff715076b494e2a0a2872"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#a9b28f21fc20c9b3076290e62cc3328e">DEFINE_SYNC_CLASS</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>DEFINE_SYNC_CLASS</code> macro inserts members to class which are needed to synchronize access to an object. Synchronization is don by using <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros.  <a href="#a9b28f21fc20c9b3076290e62cc3328e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#cf483d73b501ee7ae6b30392750b91d9">LOCK</a>(LOCK_NAME)&nbsp;&nbsp;&nbsp;( LOCK_NAME ).Lock()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Macro is used to acquire access to critical section protected by synchronization object (GaSectionLock and GaCriticalSection).  <a href="#cf483d73b501ee7ae6b30392750b91d9"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#3f31de631036bb2dfd50c01f4d57278c">UNLOCK</a>(LOCK_NAME)&nbsp;&nbsp;&nbsp;( LOCK_NAME ).Unlock()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Macro is used when thread exits critical section and releases access to synchronization object (GaSectionLock and GaCriticalSection).  <a href="#3f31de631036bb2dfd50c01f4d57278c"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#0648a53ad3828a2752d23d0916e81c6d">LOCK_OBJECT</a>(LOCK_NAME, OBJECT)&nbsp;&nbsp;&nbsp;<a class="el" href="class_threading_1_1_ga_section_lock.html">Threading::GaSectionLock</a> LOCK_NAME( ( OBJECT )-&gt;GetSynchronizator(), true )</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Macro acquires access to an object with built-in synchronizator and prevents concurrent access. It instantiate GaSectionLock object with name lock and acquire access to the object, when execution leave the scope in which <code>LOCK_OBJECT</code> is specified, GaSectionLock object is destroyed and access to the locked object is released. Unlocking access to the object before leaving scope can be done by calling <code><a class="el" href="_threading_8h.html#3f31de631036bb2dfd50c01f4d57278c" title="Macro is used when thread exits critical section and releases access to synchronization...">UNLOCK(lock_name)</a></code> macro.  <a href="#0648a53ad3828a2752d23d0916e81c6d"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">#define&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="_threading_8h.html#c86ec6b84b13398c5dc211ec2df9a9cb">LOCK_THIS_OBJECT</a>(LOCK_NAME)&nbsp;&nbsp;&nbsp;<a class="el" href="class_threading_1_1_ga_section_lock.html">Threading::GaSectionLock</a> LOCK_NAME( &amp;this-&gt;_synchronizator, true )</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Macro acquires access to this and prevents concurrent access. It declares and instantiates GaSectionLock object with name lock and acquire access to this object, when execution leave the scope in which <code>LOCK_OBJECT</code> is specified, GaSectionLock object is destroyed and access to this object is released. Unlocking access to this before leaving scope can be done by calling <code><a class="el" href="_threading_8h.html#3f31de631036bb2dfd50c01f4d57278c" title="Macro is used when thread exits critical section and releases access to synchronization...">UNLOCK(lock_name)</a></code> macro.  <a href="#c86ec6b84b13398c5dc211ec2df9a9cb"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Typedefs</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#c39ee516ee1ae88f49548b9c9e5f99f1">Threading::SystemThread</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This type defines system specific type for storing threads objects or handles to them.  <a href="#c39ee516ee1ae88f49548b9c9e5f99f1"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#a83f689982d39ae995a27164fdd8386e">Threading::SysSyncObject</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This type defines system specific type for storing synchronization objects or handles to them. System specific synchronization is wrapped by <a class="el" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">GaCriticalSection</a> class.  <a href="#a83f689982d39ae995a27164fdd8386e"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#82f4c88f477687593b6312dd4ddf4daf">Threading::SysSemaphoreObject</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This type defines system specific type for storing semaphores objects or handles to them. Manipulation over semaphores is done by <code>MAKE_SEMAPHORE</code>, <code>FREE_SEMAPHORE</code>, <code>LOCK_SEMAPHORE</code> and <code>UNLOCK_SEMAPHORE</code> macros.  <a href="#82f4c88f477687593b6312dd4ddf4daf"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#d35f325115178850c2dfd5b55d10166b">Threading::SysEventObject</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This type defines system specific type for storing events objects or handles to them. Manipulation over events is done by <code>MAKE_EVENT</code>, <code>FREE_EVENT</code>, <code>WAIT_FOR_EVENT</code> and <code>SIGNAL_EVENT</code> macros.  <a href="#d35f325115178850c2dfd5b55d10166b"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#1ced7e2f567ba5ae9bd76aaa8b6e72b6">Threading::ThreadFunctionReturn</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This type is used as return value type for functions which are used as threads' entry points. This type hides system specific types which are used for the purpose.  <a href="#1ced7e2f567ba5ae9bd76aaa8b6e72b6"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef <br>
_SYSTEM_OR_COMPILER_SPECIFIC_&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#2fb902107a773c3f7cc8e52847f77212">Threading::ThreadID</a></td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Variables/objects of this type are used for storing threads' IDs. This type hides system specific types which are used for the purpose.  <a href="#2fb902107a773c3f7cc8e52847f77212"></a><br></td></tr>
<tr><td colspan="2"><br><h2>Enumerations</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">enum &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aa">Threading::GaThreadStatus</a> { <a class="el" href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aab5bea800136b60c6294c477a67b82529">Threading::GATS_RUNNING</a> =  0x1, 
<a class="el" href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aab54a40184c1981d65d25559ba6ff9a26">Threading::GATS_STOPPED</a> =  0x2, 
<a class="el" href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aadf256fcdf7ba11725937d2c8a17b06a0">Threading::GATS_PAUSED</a> =  0x4, 
<a class="el" href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aa6e0d93935565aee382768b9e28781362">Threading::GATS_NOT_RUNNING</a> =  GATS_STOPPED | GATS_PAUSED
 }</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This enumeration defines possible states of threads.  <a href="namespace_threading.html#a6bee8e9f7890591792c78852f0955aa">More...</a><br></td></tr>
<tr><td colspan="2"><br><h2>Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#011b400f69a82fbb5ede2436002485d2">Threading::MakeSemaphore</a> (SysSemaphoreObject &amp;semaphoreHandle, int maxCount, int initialCount)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to create operating system object for semaphore and to initialize it.  <a href="#011b400f69a82fbb5ede2436002485d2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#5d8ff1beb0e8877019a13adc4ac269e7">Threading::DeleteSemaphore</a> (SysSemaphoreObject &amp;semaphoreHandle)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to free operating system semaphore.  <a href="#5d8ff1beb0e8877019a13adc4ac269e7"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#d3133ef64c6b40bacc1eecaec9a71eb3">Threading::LockSemaphore</a> (SysSemaphoreObject &amp;semaphoreHandle)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to acquire access to critical section protected by semaphore.  <a href="#d3133ef64c6b40bacc1eecaec9a71eb3"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#2d49e8ec034bc22671b7a64566d974e7">Threading::UnlockSemaphore</a> (SysSemaphoreObject &amp;semaphoreHandle, int count)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to release access to critical section protected by semaphore.  <a href="#2d49e8ec034bc22671b7a64566d974e7"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#bfbd486894459c5b901cc511335101bc">Threading::MakeEvent</a> (SysEventObject &amp;eventHandle, bool intialState)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to create operating system object for event and to initialize it.  <a href="#bfbd486894459c5b901cc511335101bc"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#89b0439626b7bbf9cca17831cb3f2aa8">Threading::DeleteEvent</a> (SysEventObject &amp;eventHandle)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to free operating system semaphore.  <a href="#89b0439626b7bbf9cca17831cb3f2aa8"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#90d344714856f6b3eb5589bc2ee31f3a">Threading::WaitForEvent</a> (SysEventObject &amp;eventHandle)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to block calling thread until event reaches signaled state. When calling thread is released, event is restared to non-signaled state.  <a href="#90d344714856f6b3eb5589bc2ee31f3a"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#8ae164997c3136f1625142675ea39562">Threading::SignalEvent</a> (SysEventObject &amp;eventHandle)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function is used to set event to signaled state.  <a href="#8ae164997c3136f1625142675ea39562"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">typedef&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="namespace_threading.html#a775501be708d92cb6c7954590d7fd82">Threading::ThreadFunctionReturn</a> (GACALL *ThreadFunctionPointer)(GaThread *</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><code>ThreadFunctionPointer</code> is pointer to function used as thread's entry point. Entry point function must obey restriction of this type: <br>
1. Function must return value of <a class="el" href="namespace_threading.html#1ced7e2f567ba5ae9bd76aaa8b6e72b6" title="This type is used as return value type for functions which are used as threads&#39;...">ThreadFunctionReturn</a> type. <br>
2. Function must use <code>GACALL</code> calling convention. <br>
3. Function must have two parameters. <br>
4. First parameter must be pointer <a class="el" href="class_threading_1_1_ga_thread.html" title="GaThread class controls system threads. It wraps system specific control of threading...">GaThread</a> (<a class="el" href="class_threading_1_1_ga_thread.html" title="GaThread class controls system threads. It wraps system specific control of threading...">GaThread</a>*). <br>
5. Second parameter must be pointer to <code>void</code> (<code>void</code>*).  <a href="#a775501be708d92cb6c7954590d7fd82"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
This file contains declaration of classes and types used to abstract operating system specific threads control. 
<p>
<hr><h2>Define Documentation</h2>
<a class="anchor" name="dbe76a6042d420484798146558d9f374"></a><!-- doxytag: member="Threading.h::ATOMIC_DEC" ref="dbe76a6042d420484798146558d9f374" args="(VALUE)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define ATOMIC_DEC          </td>
          <td>(</td>
          <td class="paramtype">VALUE&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;InterlockedDecrement( (LONG*)&amp;VALUE )</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>ATOMIC_DEC</code> macro atomically decrements <code>VALUE</code> by one and returns new value. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>VALUE</em>&nbsp;</td><td>variable which is decremented.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="dbe76a6042d420484798146558d9f374"></a><!-- doxytag: member="Threading.h::ATOMIC_DEC" ref="dbe76a6042d420484798146558d9f374" args="(VALUE)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define ATOMIC_DEC          </td>
          <td>(</td>
          <td class="paramtype">VALUE&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>ATOMIC_DEC</code> macro atomically decrements <code>VALUE</code> by one and returns new value. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>VALUE</em>&nbsp;</td><td>variable which is decremented.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a85596536fefa7f93352463a0a79a2fd"></a><!-- doxytag: member="Threading.h::ATOMIC_INC" ref="a85596536fefa7f93352463a0a79a2fd" args="(VALUE)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define ATOMIC_INC          </td>
          <td>(</td>
          <td class="paramtype">VALUE&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;InterlockedIncrement( (LONG*)&amp;VALUE )</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>ATOMIC_INC</code> macro atomically increments <code>VALUE</code> by one and returns new value. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>VALUE</em>&nbsp;</td><td>variable which is incremented.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a85596536fefa7f93352463a0a79a2fd"></a><!-- doxytag: member="Threading.h::ATOMIC_INC" ref="a85596536fefa7f93352463a0a79a2fd" args="(VALUE)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define ATOMIC_INC          </td>
          <td>(</td>
          <td class="paramtype">VALUE&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>ATOMIC_INC</code> macro atomically increments <code>VALUE</code> by one and returns new value. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>VALUE</em>&nbsp;</td><td>variable which is incremented.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="a9b28f21fc20c9b3076290e62cc3328e"></a><!-- doxytag: member="Threading.h::DEFINE_SYNC_CLASS" ref="a9b28f21fc20c9b3076290e62cc3328e" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define DEFINE_SYNC_CLASS          </td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<b>Value:</b><div class="fragment"><pre class="fragment"><span class="keyword">protected</span>: <span class="keyword">mutable</span> <a class="code" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">Threading::GaCriticalSection</a> _synchronizator; \
                                                                <span class="keyword">public</span>: <a class="code" href="class_threading_1_1_ga_critical_section.html" title="GaCriticalSection class is wrapper class for system synchronization object.">Threading::GaCriticalSection</a>* <a class="code" href="_platform_8h.html#8ca6b7c8338204f84fd10412e4e9daf7" title="Defines calling convention used by GAL. For all supported systems and compilers except...">GACALL</a> GetSynchronizator() const \
                                                                                        { <span class="keywordflow">return</span> &amp;_synchronizator; }
</pre></div><code>DEFINE_SYNC_CLASS</code> macro inserts members to class which are needed to synchronize access to an object. Synchronization is don by using <code>LOCK_OBJECT</code> and <code>LOCK_THIS_OBJECT</code> macros. 
<p>

</div>
</div><p>
<a class="anchor" name="cf483d73b501ee7ae6b30392750b91d9"></a><!-- doxytag: member="Threading.h::LOCK" ref="cf483d73b501ee7ae6b30392750b91d9" args="(LOCK_NAME)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LOCK          </td>
          <td>(</td>
          <td class="paramtype">LOCK_NAME&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;( LOCK_NAME ).Lock()</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Macro is used to acquire access to critical section protected by synchronization object (GaSectionLock and GaCriticalSection). 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK_NAME</em>&nbsp;</td><td>synchronization object.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="0648a53ad3828a2752d23d0916e81c6d"></a><!-- doxytag: member="Threading.h::LOCK_OBJECT" ref="0648a53ad3828a2752d23d0916e81c6d" args="(LOCK_NAME, OBJECT)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LOCK_OBJECT          </td>
          <td>(</td>
          <td class="paramtype">LOCK_NAME,         <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">OBJECT&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;<a class="el" href="class_threading_1_1_ga_section_lock.html">Threading::GaSectionLock</a> LOCK_NAME( ( OBJECT )-&gt;GetSynchronizator(), true )</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Macro acquires access to an object with built-in synchronizator and prevents concurrent access. It instantiate GaSectionLock object with name lock and acquire access to the object, when execution leave the scope in which <code>LOCK_OBJECT</code> is specified, GaSectionLock object is destroyed and access to the locked object is released. Unlocking access to the object before leaving scope can be done by calling <code><a class="el" href="_threading_8h.html#3f31de631036bb2dfd50c01f4d57278c" title="Macro is used when thread exits critical section and releases access to synchronization...">UNLOCK(lock_name)</a></code> macro. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK_NAME</em>&nbsp;</td><td>object which is synchronized.</td></tr>
    <tr><td valign="top"></td><td valign="top"><em>OBJECT</em>&nbsp;</td><td>name of <code>GaSectionLock</code> object.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="c86ec6b84b13398c5dc211ec2df9a9cb"></a><!-- doxytag: member="Threading.h::LOCK_THIS_OBJECT" ref="c86ec6b84b13398c5dc211ec2df9a9cb" args="(LOCK_NAME)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define LOCK_THIS_OBJECT          </td>
          <td>(</td>
          <td class="paramtype">LOCK_NAME&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;<a class="el" href="class_threading_1_1_ga_section_lock.html">Threading::GaSectionLock</a> LOCK_NAME( &amp;this-&gt;_synchronizator, true )</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Macro acquires access to this and prevents concurrent access. It declares and instantiates GaSectionLock object with name lock and acquire access to this object, when execution leave the scope in which <code>LOCK_OBJECT</code> is specified, GaSectionLock object is destroyed and access to this object is released. Unlocking access to this before leaving scope can be done by calling <code><a class="el" href="_threading_8h.html#3f31de631036bb2dfd50c01f4d57278c" title="Macro is used when thread exits critical section and releases access to synchronization...">UNLOCK(lock_name)</a></code> macro. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK_NAME</em>&nbsp;</td><td>name of <code>GaSectionLock</code> object.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="8a27192e44aff715076b494e2a0a2872"></a><!-- doxytag: member="Threading.h::SPINLOCK" ref="8a27192e44aff715076b494e2a0a2872" args="(LOCK)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define SPINLOCK          </td>
          <td>(</td>
          <td class="paramtype">LOCK&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;while( InterlockedExchange( (LONG*)&amp;LOCK, 1 ) )</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>SPINLOCK</code> macro defines mechanism of spinlock. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK</em>&nbsp;</td><td>variable that is useed as lock.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="8a27192e44aff715076b494e2a0a2872"></a><!-- doxytag: member="Threading.h::SPINLOCK" ref="8a27192e44aff715076b494e2a0a2872" args="(LOCK)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define SPINLOCK          </td>
          <td>(</td>
          <td class="paramtype">LOCK&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;_SYSTEM_OR_COMPILER_SPECIFIC_</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
<code>SPINLOCK</code> macro defines mechanism of spinlock. 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK</em>&nbsp;</td><td>variable that is useed as lock.</td></tr>
  </table>
</dl>

</div>
</div><p>
<a class="anchor" name="3f31de631036bb2dfd50c01f4d57278c"></a><!-- doxytag: member="Threading.h::UNLOCK" ref="3f31de631036bb2dfd50c01f4d57278c" args="(LOCK_NAME)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define UNLOCK          </td>
          <td>(</td>
          <td class="paramtype">LOCK_NAME&nbsp;</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td width="100%">&nbsp;&nbsp;&nbsp;( LOCK_NAME ).Unlock()</td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Macro is used when thread exits critical section and releases access to synchronization object (GaSectionLock and GaCriticalSection). 
<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
  <table border="0" cellspacing="2" cellpadding="0">
    <tr><td valign="top"></td><td valign="top"><em>LOCK_NAME</em>&nbsp;</td><td>synchronization object.</td></tr>
  </table>
</dl>

</div>
</div><p>
</div>
<br/><a href="http://www.coolsoft-sd.com/ProductVersion.aspx?vid=9">Genetic Algorithm Library</a><br/><a href="http://www.coolsoft-sd.com/">Coolsoft Software Development</a>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
Serbia Serbia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions