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

📄 glib-threads.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>Threads</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-core.html" title="GLib Core Application Support"><link rel="prev" href="glib-The-Main-Event-Loop.html" title="The Main Event Loop"><link rel="next" href="glib-Thread-Pools.html" title="Thread Pools"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-The-Main-Event-Loop.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-core.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-Thread-Pools.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id2881157" class="shortcut">Top</a>                  &#160;|&#160;                  <a href="#id2882742" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-Threads"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id2881157"></a><span class="refentrytitle">Threads</span></h2><p>Threads &#8212; thread abstraction; including threads, different mutexes, conditionsand thread private data</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include &lt;glib.h&gt;#define             <a class="link" href="glib-Threads.html#G-THREADS-ENABLED:CAPS">G_THREADS_ENABLED</a>#define             <a class="link" href="glib-Threads.html#G-THREADS-IMPL-POSIX:CAPS">G_THREADS_IMPL_POSIX</a>#define             <a class="link" href="glib-Threads.html#G-THREADS-IMPL-NONE:CAPS">G_THREADS_IMPL_NONE</a>#define             <a class="link" href="glib-Threads.html#G-THREAD-ERROR:CAPS">G_THREAD_ERROR</a>enum                <a class="link" href="glib-Threads.html#GThreadError">GThreadError</a>;                    <a class="link" href="glib-Threads.html#GThreadFunctions">GThreadFunctions</a>;void                <a class="link" href="glib-Threads.html#g-thread-init">g_thread_init</a>                       (<a class="link" href="glib-Threads.html#GThreadFunctions">GThreadFunctions</a> *vtable);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-thread-supported">g_thread_supported</a>                  ();<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            (<a class="link" href="glib-Threads.html#GThreadFunc">*GThreadFunc</a>)                      (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data);enum                <a class="link" href="glib-Threads.html#GThreadPriority">GThreadPriority</a>;                    <a class="link" href="glib-Threads.html#GThread">GThread</a>;<a class="link" href="glib-Threads.html#GThread">GThread</a>*            <a class="link" href="glib-Threads.html#g-thread-create">g_thread_create</a>                     (<a class="link" href="glib-Threads.html#GThreadFunc">GThreadFunc</a> func,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data,                                                         <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> joinable,                                                         <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Threads.html#GThread">GThread</a>*            <a class="link" href="glib-Threads.html#g-thread-create-full">g_thread_create_full</a>                (<a class="link" href="glib-Threads.html#GThreadFunc">GThreadFunc</a> func,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data,                                                         <a class="link" href="glib-Basic-Types.html#gulong">gulong</a> stack_size,                                                         <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> joinable,                                                         <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> bound,                                                         <a class="link" href="glib-Threads.html#GThreadPriority">GThreadPriority</a> priority,                                                         <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Threads.html#GThread">GThread</a>*            <a class="link" href="glib-Threads.html#g-thread-self">g_thread_self</a>                       (void);<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Threads.html#g-thread-join">g_thread_join</a>                       (<a class="link" href="glib-Threads.html#GThread">GThread</a> *thread);void                <a class="link" href="glib-Threads.html#g-thread-set-priority">g_thread_set_priority</a>               (<a class="link" href="glib-Threads.html#GThread">GThread</a> *thread,                                                         <a class="link" href="glib-Threads.html#GThreadPriority">GThreadPriority</a> priority);void                <a class="link" href="glib-Threads.html#g-thread-yield">g_thread_yield</a>                      ();void                <a class="link" href="glib-Threads.html#g-thread-exit">g_thread_exit</a>                       (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> retval);void                <a class="link" href="glib-Threads.html#g-thread-foreach">g_thread_foreach</a>                    (<a class="link" href="glib-Doubly-Linked-Lists.html#GFunc">GFunc</a> thread_func,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);                    <a class="link" href="glib-Threads.html#GMutex">GMutex</a>;<a class="link" href="glib-Threads.html#GMutex">GMutex</a>*             <a class="link" href="glib-Threads.html#g-mutex-new">g_mutex_new</a>                         ();void                <a class="link" href="glib-Threads.html#g-mutex-lock">g_mutex_lock</a>                        (<a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-mutex-trylock">g_mutex_trylock</a>                     (<a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-mutex-unlock">g_mutex_unlock</a>                      (<a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-mutex-free">g_mutex_free</a>                        (<a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex);                    <a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a>;#define             <a class="link" href="glib-Threads.html#G-STATIC-MUTEX-INIT:CAPS">G_STATIC_MUTEX_INIT</a>void                <a class="link" href="glib-Threads.html#g-static-mutex-init">g_static_mutex_init</a>                 (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-mutex-lock">g_static_mutex_lock</a>                 (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-static-mutex-trylock">g_static_mutex_trylock</a>              (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-mutex-unlock">g_static_mutex_unlock</a>               (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);<a class="link" href="glib-Threads.html#GMutex">GMutex</a>*             <a class="link" href="glib-Threads.html#g-static-mutex-get-mutex">g_static_mutex_get_mutex</a>            (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-mutex-free">g_static_mutex_free</a>                 (<a class="link" href="glib-Threads.html#GStaticMutex">GStaticMutex</a> *mutex);#define             <a class="link" href="glib-Threads.html#G-LOCK-DEFINE:CAPS">G_LOCK_DEFINE</a>                       (name)#define             <a class="link" href="glib-Threads.html#G-LOCK-DEFINE-STATIC:CAPS">G_LOCK_DEFINE_STATIC</a>                (name)#define             <a class="link" href="glib-Threads.html#G-LOCK-EXTERN:CAPS">G_LOCK_EXTERN</a>                       (name)#define             <a class="link" href="glib-Threads.html#G-LOCK:CAPS">G_LOCK</a>                              (name)#define             <a class="link" href="glib-Threads.html#G-TRYLOCK:CAPS">G_TRYLOCK</a>                           (name)#define             <a class="link" href="glib-Threads.html#G-UNLOCK:CAPS">G_UNLOCK</a>                            (name)                    <a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a>;#define             <a class="link" href="glib-Threads.html#G-STATIC-REC-MUTEX-INIT:CAPS">G_STATIC_REC_MUTEX_INIT</a>void                <a class="link" href="glib-Threads.html#g-static-rec-mutex-init">g_static_rec_mutex_init</a>             (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-rec-mutex-lock">g_static_rec_mutex_lock</a>             (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-static-rec-mutex-trylock">g_static_rec_mutex_trylock</a>          (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-rec-mutex-unlock">g_static_rec_mutex_unlock</a>           (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-rec-mutex-lock-full">g_static_rec_mutex_lock_full</a>        (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex,                                                         <a class="link" href="glib-Basic-Types.html#guint">guint</a> depth);<a class="link" href="glib-Basic-Types.html#guint">guint</a>               <a class="link" href="glib-Threads.html#g-static-rec-mutex-unlock-full">g_static_rec_mutex_unlock_full</a>      (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);void                <a class="link" href="glib-Threads.html#g-static-rec-mutex-free">g_static_rec_mutex_free</a>             (<a class="link" href="glib-Threads.html#GStaticRecMutex">GStaticRecMutex</a> *mutex);                    <a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a>;#define             <a class="link" href="glib-Threads.html#G-STATIC-RW-LOCK-INIT:CAPS">G_STATIC_RW_LOCK_INIT</a>void                <a class="link" href="glib-Threads.html#g-static-rw-lock-init">g_static_rw_lock_init</a>               (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);void                <a class="link" href="glib-Threads.html#g-static-rw-lock-reader-lock">g_static_rw_lock_reader_lock</a>        (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-static-rw-lock-reader-trylock">g_static_rw_lock_reader_trylock</a>     (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);void                <a class="link" href="glib-Threads.html#g-static-rw-lock-reader-unlock">g_static_rw_lock_reader_unlock</a>      (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);void                <a class="link" href="glib-Threads.html#g-static-rw-lock-writer-lock">g_static_rw_lock_writer_lock</a>        (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-static-rw-lock-writer-trylock">g_static_rw_lock_writer_trylock</a>     (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);void                <a class="link" href="glib-Threads.html#g-static-rw-lock-writer-unlock">g_static_rw_lock_writer_unlock</a>      (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);void                <a class="link" href="glib-Threads.html#g-static-rw-lock-free">g_static_rw_lock_free</a>               (<a class="link" href="glib-Threads.html#GStaticRWLock">GStaticRWLock</a> *lock);                    <a class="link" href="glib-Threads.html#GCond">GCond</a>;<a class="link" href="glib-Threads.html#GCond">GCond</a>*              <a class="link" href="glib-Threads.html#g-cond-new">g_cond_new</a>                          ();void                <a class="link" href="glib-Threads.html#g-cond-signal">g_cond_signal</a>                       (<a class="link" href="glib-Threads.html#GCond">GCond</a> *cond);void                <a class="link" href="glib-Threads.html#g-cond-broadcast">g_cond_broadcast</a>                    (<a class="link" href="glib-Threads.html#GCond">GCond</a> *cond);void                <a class="link" href="glib-Threads.html#g-cond-wait">g_cond_wait</a>                         (<a class="link" href="glib-Threads.html#GCond">GCond</a> *cond,                                                         <a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-cond-timed-wait">g_cond_timed_wait</a>                   (<a class="link" href="glib-Threads.html#GCond">GCond</a> *cond,                                                         <a class="link" href="glib-Threads.html#GMutex">GMutex</a> *mutex,                                                         <a class="link" href="glib-Date-and-Time-Functions.html#GTimeVal">GTimeVal</a> *abs_time);void                <a class="link" href="glib-Threads.html#g-cond-free">g_cond_free</a>                         (<a class="link" href="glib-Threads.html#GCond">GCond</a> *cond);                    <a class="link" href="glib-Threads.html#GPrivate">GPrivate</a>;<a class="link" href="glib-Threads.html#GPrivate">GPrivate</a>*           <a class="link" href="glib-Threads.html#g-private-new">g_private_new</a>                       (<a class="link" href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> destructor);<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Threads.html#g-private-get">g_private_get</a>                       (<a class="link" href="glib-Threads.html#GPrivate">GPrivate</a> *private_key);void                <a class="link" href="glib-Threads.html#g-private-set">g_private_set</a>                       (<a class="link" href="glib-Threads.html#GPrivate">GPrivate</a> *private_key,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data);                    <a class="link" href="glib-Threads.html#GStaticPrivate">GStaticPrivate</a>;#define             <a class="link" href="glib-Threads.html#G-STATIC-PRIVATE-INIT:CAPS">G_STATIC_PRIVATE_INIT</a>void                <a class="link" href="glib-Threads.html#g-static-private-init">g_static_private_init</a>               (<a class="link" href="glib-Threads.html#GStaticPrivate">GStaticPrivate</a> *private_key);<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a>            <a class="link" href="glib-Threads.html#g-static-private-get">g_static_private_get</a>                (<a class="link" href="glib-Threads.html#GStaticPrivate">GStaticPrivate</a> *private_key);void                <a class="link" href="glib-Threads.html#g-static-private-set">g_static_private_set</a>                (<a class="link" href="glib-Threads.html#GStaticPrivate">GStaticPrivate</a> *private_key,                                                         <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data,                                                         <a class="link" href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> notify);void                <a class="link" href="glib-Threads.html#g-static-private-free">g_static_private_free</a>               (<a class="link" href="glib-Threads.html#GStaticPrivate">GStaticPrivate</a> *private_key);                    <a class="link" href="glib-Threads.html#GOnce">GOnce</a>;enum                <a class="link" href="glib-Threads.html#GOnceStatus">GOnceStatus</a>;#define             <a class="link" href="glib-Threads.html#G-ONCE-INIT:CAPS">G_ONCE_INIT</a>#define             <a class="link" href="glib-Threads.html#g-once">g_once</a>                              (once, func, arg)<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            <a class="link" href="glib-Threads.html#g-once-init-enter">g_once_init_enter</a>                   (volatile <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *value_location);void                <a class="link" href="glib-Threads.html#g-once-init-leave">g_once_init_leave</a>                   (volatile <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *value_location,                                                         <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> initialization_value);</pre></div><div class="refsect1" lang="en"><a name="id2882742"></a><h2>Description</h2><p>Threads act almost like processes, but unlike processes all threads ofone process share the same memory. This is good, as it provides easycommunication between the involved threads via this shared memory, andit is bad, because strange things (so called "Heisenbugs") mighthappen if the program is not carefully designed. In particular, due tothe concurrent nature of threads, no assumptions on the order ofexecution of code running in different threads can be made, unlessorder is explicitly forced by the programmer through synchronizationprimitives.</p><p>The aim of the thread related functions in GLib is to provide aportable means for writing multi-threaded software. There areprimitives for mutexes to protect the access to portions of memory(<a class="link" href="glib-Threads.html#GMutex"><span class="type">GMutex</span></a>, <a class="link" href="glib-Threads.html#GStaticMutex"><span class="type">GStaticMutex</span></a>, <a class="link" href="glib-Threads.html#G-LOCK-DEFINE:CAPS"><span class="type">G_LOCK_DEFINE</span></a>, <a class="link" href="glib-Threads.html#GStaticRecMutex"><span class="type">GStaticRecMutex</span></a> and<a class="link" href="glib-Threads.html#GStaticRWLock"><span class="type">GStaticRWLock</span></a>). There are primitives for condition variables to allowsynchronization of threads (<a class="link" href="glib-Threads.html#GCond"><span class="type">GCond</span></a>).  There are primitivesfor thread-private data - data that every thread has a private instance of(<a class="link" href="glib-Threads.html#GPrivate"><span class="type">GPrivate</span></a>, <a class="link" href="glib-Threads.html#GStaticPrivate"><span class="type">GStaticPrivate</span></a>). Last but definitely not least there areprimitives to portably create and manage threads (<a class="link" href="glib-Threads.html#GThread"><span class="type">GThread</span></a>).</p><p>You must call <a class="link" href="glib-Threads.html#g-thread-init"><code class="function">g_thread_init()</code></a> before executing any other GLibfunctions in a threaded GLib program. After that, GLib is completelythread safe (all global data is automatically locked), but individualdata structure instances are not automatically locked for performancereasons. So, for example you must coordinate accesses to the same<a class="link" href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a> from multiple threads.  The two notable exceptions fromthis rule are <a class="link" href="glib-The-Main-Event-Loop.html#GMainLoop"><span class="type">GMainLoop</span></a> and <a class="link" href="glib-Asynchronous-Queues.html#GAsyncQueue"><span class="type">GAsyncQueue</span></a>,which <span class="emphasis"><em>are</em></span> threadsafe and needs no furtherapplication-level locking to be accessed from multiple threads.</p><p>To help debugging problems in multithreaded applications, GLib supportserror-checking mutexes that will give you helpful error messages oncommon problems. To use error-checking mutexes, define the symbol <span class="type">G_ERRORCHECK_MUTEXES</span> when compiling the application.</p></div><div class="refsect1" lang="en"><a name="id2882918"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id2882928"></a><h3><a name="G-THREADS-ENABLED:CAPS"></a>G_THREADS_ENABLED</h3><a class="indexterm" name="id2882942"></a><pre class="programlisting">#define G_THREADS_ENABLED

⌨️ 快捷键说明

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