⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-threads.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</pre><p>This macro is defined if GLib was compiled with thread support. Thisdoes not necessarily mean that there is a thread implementationavailable, but it does mean that the infrastructure is in place andthat once you provide a thread implementation to <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a>, GLibwill be multi-thread safe. If <a class="link" href="glib-Threads.html#G-THREADS-ENABLED:CAPS"><span class="type">G_THREADS_ENABLED</span></a> is not defined, thenGlib is not, and cannot be, multi-thread safe.</p></div><hr><div class="refsect2" lang="en"><a name="id2882982"></a><h3><a name="G-THREADS-IMPL-POSIX:CAPS"></a>G_THREADS_IMPL_POSIX</h3><a class="indexterm" name="id2882995"></a><pre class="programlisting">#define G_THREADS_IMPL_POSIX</pre><p>This macro is defined if POSIX style threads are used.</p></div><hr><div class="refsect2" lang="en"><a name="id2883011"></a><h3><a name="G-THREADS-IMPL-NONE:CAPS"></a>G_THREADS_IMPL_NONE</h3><a class="indexterm" name="id2883025"></a><pre class="programlisting">#define G_THREADS_IMPL_NONE</pre><p>This macro is defined if no thread implementation is used. You can,however, provide one to <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> to make GLib multi-thread safe.</p></div><hr><div class="refsect2" lang="en"><a name="id2883053"></a><h3><a name="G-THREAD-ERROR:CAPS"></a>G_THREAD_ERROR</h3><a class="indexterm" name="id2883066"></a><pre class="programlisting">#define G_THREAD_ERROR g_thread_error_quark ()</pre><p>The error domain of the GLib thread subsystem.</p></div><hr><div class="refsect2" lang="en"><a name="id2883082"></a><h3><a name="GThreadError"></a>enum GThreadError</h3><a class="indexterm" name="id2883095"></a><pre class="programlisting">typedef enum{  G_THREAD_ERROR_AGAIN /* Resource temporarily unavailable */} GThreadError;</pre><p>Possible errors of thread related functions.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="G-THREAD-ERROR-AGAIN:CAPS"></a><code class="literal">G_THREAD_ERROR_AGAIN</code></span></p></td><td>a thread couldn't be created due to resourceshortage. Try again later.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2883140"></a><h3><a name="GThreadFunctions"></a>GThreadFunctions</h3><a class="indexterm" name="id2883152"></a><pre class="programlisting">typedef struct {  GMutex*  (*mutex_new)           (void);  void     (*mutex_lock)          (GMutex               *mutex);  gboolean (*mutex_trylock)       (GMutex               *mutex);  void     (*mutex_unlock)        (GMutex               *mutex);  void     (*mutex_free)          (GMutex               *mutex);  GCond*   (*cond_new)            (void);  void     (*cond_signal)         (GCond                *cond);  void     (*cond_broadcast)      (GCond                *cond);  void     (*cond_wait)           (GCond                *cond,                                   GMutex               *mutex);  gboolean (*cond_timed_wait)     (GCond                *cond,                                   GMutex               *mutex,                                   GTimeVal             *end_time);  void      (*cond_free)          (GCond                *cond);  GPrivate* (*private_new)        (GDestroyNotify        destructor);  gpointer  (*private_get)        (GPrivate             *private_key);  void      (*private_set)        (GPrivate             *private_key,                                   gpointer              data);  void      (*thread_create)      (GThreadFunc           func,                                   gpointer              data,                                   gulong                stack_size,                                   gboolean              joinable,                                   gboolean              bound,                                   GThreadPriority       priority,                                   gpointer              thread,                                   GError              **error);  void      (*thread_yield)       (void);  void      (*thread_join)        (gpointer              thread);  void      (*thread_exit)        (void);  void      (*thread_set_priority)(gpointer              thread,                                   GThreadPriority       priority);  void      (*thread_self)        (gpointer              thread);  gboolean  (*thread_equal)       (gpointer              thread1,				   gpointer              thread2);} GThreadFunctions;</pre><p>This function table is used by <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> to initialize thethread system. The functions in the table are directly used by theirg_* prepended counterparts (described in this document).  For example,if you call <a class="link" href="glib-Threads.html#g-mutex-new"><code class="function">g_mutex_new()</code></a> then <code class="function">mutex_new()</code> from the table provided to<a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> will be called.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Do not use this struct unless you know what you are doing.</p></div></div><hr><div class="refsect2" lang="en"><a name="id2883258"></a><h3><a name="g-thread-init"></a>g_thread_init ()</h3><a class="indexterm" name="id2883271"></a><pre class="programlisting">void                g_thread_init                       (<a class="link" href="glib-Threads.html#GThreadFunctions">GThreadFunctions</a> *vtable);</pre><p>If you use GLib from more than one thread, you must initializethe thread system by calling <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a>. Most of the time you will only have to call <code class="literal">g_thread_init (NULL)</code>. </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Do not call <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> with a non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> parameter unless youreally know what you are doing.</p></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p><a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> must not be called directly or indirectly as acallback from GLib. Also no mutexes may be currently locked whilecalling <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a>.</p></div><p><a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> might only be called once. On the second callit will abort with an error. If you want to make sure that the threadsystem is initialized, you can do this:</p><p></p><div class="informalexample"><pre class="programlisting">if (!g_thread_supported ()) g_thread_init (NULL);</pre></div><p></p><p>After that line, either the thread system is initialized or, if nothread system is available in GLib (i.e. either <a class="link" href="glib-Threads.html#G-THREADS-ENABLED:CAPS"><span class="type">G_THREADS_ENABLED</span></a> isnot defined or <a class="link" href="glib-Threads.html#G-THREADS-IMPL-NONE:CAPS"><span class="type">G_THREADS_IMPL_NONE</span></a> is defined), the program willabort.</p><p>If no thread system is available and <em class="parameter"><code>vtable</code></em> is <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> or if not allelements of <em class="parameter"><code>vtable</code></em> are non-<a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>, then <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> will abort.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>To use <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> in your program, you have to link with thelibraries that the command <span class="command"><strong>pkg-config --libs gthread-2.0</strong></span> outputs. This is not the case for all the other thread related functions ofGLib. Those can be used without having to link with the thread libraries.</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>vtable</code></em>&#160;:</span></p></td><td>a function table of type <a class="link" href="glib-Threads.html#GThreadFunctions"><span class="type">GThreadFunctions</span></a>, that provides theentry points to the thread system to be used.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2883534"></a><h3><a name="g-thread-supported"></a>g_thread_supported ()</h3><a class="indexterm" name="id2883548"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            g_thread_supported                  ();</pre><p>This function returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the thread system is initialized, and<a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if it is not.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This function is actually a macro. Apart from taking the address of ityou can however use it as if it was a function.</p></div><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td><a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, if the thread system is initialized.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2883623"></a><h3><a name="GThreadFunc"></a>GThreadFunc ()</h3><a class="indexterm" name="id2883636"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            (*GThreadFunc)                      (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data);</pre><p>Specifies the type of the <em class="parameter"><code>func</code></em> functions passed to<a class="link" href="glib-Threads.html#g-thread-create"><code class="function">g_thread_create()</code></a> or <a class="link" href="glib-Threads.html#g-thread-create-full"><code class="function">g_thread_create_full()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top">

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -