1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * gthread.c: posix thread system implementation
5 * Copyright 1998 Sebastian Wilhelmi; University of Karlsruhe
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
25 * file for a list of people on the GLib Team. See the ChangeLog
26 * files for a list of changes. These files are distributed with
27 * GLib at ftp://ftp.gtk.org/pub/gtk/.
30 /* The GMutex, GCond and GPrivate implementations in this file are some
31 * of the lowest-level code in GLib. All other parts of GLib (messages,
32 * memory, slices, etc) assume that they can freely use these facilities
33 * without risking recursion.
35 * As such, these functions are NOT permitted to call any other part of
38 * The thread manipulation functions (create, exit, join, etc.) have
39 * more freedom -- they can do as they please.
46 #include "gthreadprivate.h"
48 #include "gmessages.h"
49 #include "gstrfuncs.h"
57 #ifdef HAVE_SYS_TIME_H
58 # include <sys/time.h>
66 #ifdef HAVE_SYS_PRCTL_H
67 #include <sys/prctl.h>
71 g_thread_abort (gint status,
72 const gchar *function)
74 fprintf (stderr, "GLib (gthread-posix.c): Unexpected error from C library during '%s': %s. Aborting.\n",
75 strerror (status), function);
83 * @mutex: an uninitialized #GMutex
85 * Initializes a #GMutex so that it can be used.
87 * This function is useful to initialize a mutex that has been
88 * allocated on the stack, or as part of a larger structure.
89 * It is not necessary to initialize a mutex that has been
90 * created with g_mutex_new(). Also see #G_MUTEX_INIT for an
91 * alternative way to initialize statically allocated mutexes.
101 * b = g_new (Blob, 1);
102 * g_mutex_init (&b->m);
105 * To undo the effect of g_mutex_init() when a mutex is no longer
106 * needed, use g_mutex_clear().
108 * Calling g_mutex_init() on an already initialized #GMutex leads
109 * to undefined behaviour.
114 g_mutex_init (GMutex *mutex)
117 pthread_mutexattr_t *pattr = NULL;
118 #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
119 pthread_mutexattr_t attr;
120 pthread_mutexattr_init (&attr);
121 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_ADAPTIVE_NP);
125 if G_UNLIKELY ((status = pthread_mutex_init (&mutex->impl, pattr)) != 0)
126 g_thread_abort (status, "pthread_mutex_init");
128 #ifdef PTHREAD_ADAPTIVE_MUTEX_NP
129 pthread_mutexattr_destroy (&attr);
135 * @mutex: an initialized #GMutex
137 * Frees the resources allocated to a mutex with g_mutex_init().
139 * #GMutexes that have have been created with g_mutex_new() should
140 * be freed with g_mutex_free() instead.
142 * Calling g_mutex_clear() on a locked mutex leads to undefined
148 g_mutex_clear (GMutex *mutex)
152 if G_UNLIKELY ((status = pthread_mutex_destroy (&mutex->impl)) != 0)
153 g_thread_abort (status, "pthread_mutex_destroy");
160 * Locks @mutex. If @mutex is already locked by another thread, the
161 * current thread will block until @mutex is unlocked by the other
164 * This function can be used even if g_thread_init() has not yet been
165 * called, and, in that case, will do nothing.
167 * <note>#GMutex is neither guaranteed to be recursive nor to be
168 * non-recursive, i.e. a thread could deadlock while calling
169 * g_mutex_lock(), if it already has locked @mutex. Use
170 * #GRecMutex if you need recursive mutexes.</note>
173 g_mutex_lock (GMutex *mutex)
177 if G_UNLIKELY ((status = pthread_mutex_lock (&mutex->impl)) != 0)
178 g_thread_abort (status, "pthread_mutex_lock");
185 * Unlocks @mutex. If another thread is blocked in a g_mutex_lock()
186 * call for @mutex, it will become unblocked and can lock @mutex itself.
188 * Calling g_mutex_unlock() on a mutex that is not locked by the
189 * current thread leads to undefined behaviour.
191 * This function can be used even if g_thread_init() has not yet been
192 * called, and, in that case, will do nothing.
195 g_mutex_unlock (GMutex *mutex)
199 if G_UNLIKELY ((status = pthread_mutex_unlock (&mutex->impl)) != 0)
200 g_thread_abort (status, "pthread_mutex_lock");
207 * Tries to lock @mutex. If @mutex is already locked by another thread,
208 * it immediately returns %FALSE. Otherwise it locks @mutex and returns
211 * This function can be used even if g_thread_init() has not yet been
212 * called, and, in that case, will immediately return %TRUE.
214 * <note>#GMutex is neither guaranteed to be recursive nor to be
215 * non-recursive, i.e. the return value of g_mutex_trylock() could be
216 * both %FALSE or %TRUE, if the current thread already has locked
217 * @mutex. Use #GRecMutex if you need recursive mutexes.</note>
219 * Returns: %TRUE if @mutex could be locked
222 g_mutex_trylock (GMutex *mutex)
226 if G_LIKELY ((status = pthread_mutex_trylock (&mutex->impl)) == 0)
229 if G_UNLIKELY (status != EBUSY)
230 g_thread_abort (status, "pthread_mutex_trylock");
237 static pthread_mutex_t *
238 g_rec_mutex_impl_new (void)
240 pthread_mutexattr_t attr;
241 pthread_mutex_t *mutex;
243 mutex = g_slice_new (pthread_mutex_t);
244 pthread_mutexattr_init (&attr);
245 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
246 pthread_mutex_init (mutex, &attr);
247 pthread_mutexattr_destroy (&attr);
253 g_rec_mutex_impl_free (pthread_mutex_t *mutex)
255 pthread_mutex_destroy (mutex);
256 g_slice_free (pthread_mutex_t, mutex);
259 static pthread_mutex_t *
260 g_rec_mutex_get_impl (GRecMutex *rec_mutex)
262 pthread_mutex_t *impl = rec_mutex->impl;
264 if G_UNLIKELY (rec_mutex->impl == NULL)
266 impl = g_rec_mutex_impl_new ();
267 if (!g_atomic_pointer_compare_and_exchange (&rec_mutex->impl, NULL, impl))
268 g_rec_mutex_impl_free (impl);
269 impl = rec_mutex->impl;
277 * @rec_mutex: an uninitialized #GRecMutex
279 * Initializes a #GRecMutex so that it can be used.
281 * This function is useful to initialize a recursive mutex
282 * that has been allocated on the stack, or as part of a larger
284 * It is not necessary to initialize a recursive mutex that has
285 * been created with g_rec_mutex_new(). Also see #G_REC_MUTEX_INIT
286 * for an alternative way to initialize statically allocated
297 * b = g_new (Blob, 1);
298 * g_rec_mutex_init (&b->m);
301 * Calling g_rec_mutex_init() on an already initialized #GRecMutex
302 * leads to undefined behaviour.
304 * To undo the effect of g_rec_mutex_init() when a recursive mutex
305 * is no longer needed, use g_rec_mutex_clear().
310 g_rec_mutex_init (GRecMutex *rec_mutex)
312 rec_mutex->impl = g_rec_mutex_impl_new ();
317 * @rec_mutex: an initialized #GRecMutex
319 * Frees the resources allocated to a recursive mutex with
320 * g_rec_mutex_init().
322 * #GRecMutexes that have have been created with g_rec_mutex_new()
323 * should be freed with g_rec_mutex_free() instead.
325 * Calling g_rec_mutex_clear() on a locked recursive mutex leads
326 * to undefined behaviour.
331 g_rec_mutex_clear (GRecMutex *rec_mutex)
334 g_rec_mutex_impl_free (rec_mutex->impl);
339 * @rec_mutex: a #GRecMutex
341 * Locks @rec_mutex. If @rec_mutex is already locked by another
342 * thread, the current thread will block until @rec_mutex is
343 * unlocked by the other thread. If @rec_mutex is already locked
344 * by the current thread, the 'lock count' of @rec_mutex is increased.
345 * The mutex will only become available again when it is unlocked
346 * as many times as it has been locked.
351 g_rec_mutex_lock (GRecMutex *mutex)
353 pthread_mutex_lock (g_rec_mutex_get_impl (mutex));
357 * g_rec_mutex_unlock:
358 * @rec_mutex: a #RecGMutex
360 * Unlocks @rec_mutex. If another thread is blocked in a
361 * g_rec_mutex_lock() call for @rec_mutex, it will become unblocked
362 * and can lock @rec_mutex itself.
364 * Calling g_rec_mutex_unlock() on a recursive mutex that is not
365 * locked by the current thread leads to undefined behaviour.
370 g_rec_mutex_unlock (GRecMutex *rec_mutex)
372 pthread_mutex_unlock (rec_mutex->impl);
376 * g_rec_mutex_trylock:
377 * @rec_mutex: a #GRecMutex
379 * Tries to lock @rec_mutex. If @rec_mutex is already locked
380 * by another thread, it immediately returns %FALSE. Otherwise
381 * it locks @rec_mutex and returns %TRUE.
383 * Returns: %TRUE if @rec_mutex could be locked
388 g_rec_mutex_trylock (GRecMutex *rec_mutex)
390 if (pthread_mutex_trylock (g_rec_mutex_get_impl (rec_mutex)) != 0)
400 * @rw_lock: an uninitialized #GRWLock
402 * Initializes a #GRWLock so that it can be used.
404 * This function is useful to initialize a lock that has been
405 * allocated on the stack, or as part of a larger structure.
406 * Also see #G_RW_LOCK_INIT for an alternative way to initialize
407 * statically allocated locks.
417 * b = g_new (Blob, 1);
418 * g_rw_lock_init (&b->l);
421 * To undo the effect of g_rw_lock_init() when a lock is no longer
422 * needed, use g_rw_lock_clear().
424 * Calling g_rw_lock_init() on an already initialized #GRWLock leads
425 * to undefined behaviour.
430 g_rw_lock_init (GRWLock *rw_lock)
432 pthread_rwlock_init (&rw_lock->impl, NULL);
437 * @rw_lock: an initialized #GRWLock
439 * Frees the resources allocated to a lock with g_rw_lock_init().
441 * Calling g_rw_lock_clear() when any thread holds the lock
442 * leads to undefined behaviour.
447 g_rw_lock_clear (GRWLock *rw_lock)
449 pthread_rwlock_destroy (&rw_lock->impl);
453 * g_rw_lock_writer_lock:
454 * @rw_lock: a #GRWLock
456 * Obtain a write lock on @rw_lock. If any thread already holds
457 * a read or write lock on @rw_lock, the current thread will block
458 * until all other threads have dropped their locks on @rw_lock.
463 g_rw_lock_writer_lock (GRWLock *rw_lock)
465 pthread_rwlock_wrlock (&rw_lock->impl);
469 * g_rw_lock_writer_trylock:
470 * @rw_lock: a #GRWLock
472 * Tries to obtain a write lock on @rw_lock. If any other thread holds
473 * a read or write lock on @rw_lock, it immediately returns %FALSE.
474 * Otherwise it locks @rw_lock and returns %TRUE.
476 * Returns: %TRUE if @rw_lock could be locked
481 g_rw_lock_writer_trylock (GRWLock *rw_lock)
483 if (pthread_rwlock_trywrlock (&rw_lock->impl) != 0)
490 * g_rw_lock_writer_unlock:
491 * @rw_lock: a #GRWLock
493 * Release a write lock on @rw_lock.
495 * Calling g_rw_lock_writer_unlock() on a lock that is not held
496 * by the current thread leads to undefined behaviour.
501 g_rw_lock_writer_unlock (GRWLock *rw_lock)
503 pthread_rwlock_unlock (&rw_lock->impl);
507 * g_rw_lock_reader_lock:
508 * @rw_lock: a #GRWLock
510 * Obtain a read lock on @rw_lock. If another thread currently holds
511 * the write lock on @rw_lock or blocks waiting for it, the current
512 * thread will block. Read locks can be taken recursively.
514 * It is implementation-defined how many threads are allowed to
515 * hold read locks on the same lock simultaneously.
520 g_rw_lock_reader_lock (GRWLock *rw_lock)
522 pthread_rwlock_rdlock (&rw_lock->impl);
526 * g_rw_lock_reader_trylock:
527 * @rw_lock: a #GRWLock
529 * Tries to obtain a read lock on @rw_lock and returns %TRUE if
530 * the read lock was successfully obtained. Otherwise it
533 * Returns: %TRUE if @rw_lock could be locked
538 g_rw_lock_reader_trylock (GRWLock *rw_lock)
540 if (pthread_rwlock_tryrdlock (&rw_lock->impl) != 0)
547 * g_rw_lock_reader_unlock:
548 * @rw_lock: a #GRWLock
550 * Release a read lock on @rw_lock.
552 * Calling g_rw_lock_reader_unlock() on a lock that is not held
553 * by the current thread leads to undefined behaviour.
558 g_rw_lock_reader_unlock (GRWLock *rw_lock)
560 pthread_rwlock_unlock (&rw_lock->impl);
567 * @cond: an uninitialized #GCond
569 * Initialized a #GCond so that it can be used.
571 * This function is useful to initialize a #GCond that has been
572 * allocated on the stack, or as part of a larger structure.
573 * It is not necessary to initialize a #GCond that has been
574 * created with g_cond_new(). Also see #G_COND_INIT for an
575 * alternative way to initialize statically allocated #GConds.
577 * To undo the effect of g_cond_init() when a #GCond is no longer
578 * needed, use g_cond_clear().
580 * Calling g_cond_init() on an already initialized #GCond leads
581 * to undefined behaviour.
586 g_cond_init (GCond *cond)
590 if G_UNLIKELY ((status = pthread_cond_init (&cond->impl, NULL)) != 0)
591 g_thread_abort (status, "pthread_cond_init");
596 * @cond: an initialized #GCond
598 * Frees the resources allocated to a #GCond with g_cond_init().
600 * #GConds that have been created with g_cond_new() should
601 * be freed with g_cond_free() instead.
603 * Calling g_cond_clear() for a #GCond on which threads are
604 * blocking leads to undefined behaviour.
609 g_cond_clear (GCond *cond)
613 if G_UNLIKELY ((status = pthread_cond_destroy (&cond->impl)) != 0)
614 g_thread_abort (status, "pthread_cond_destroy");
620 * @mutex: a #GMutex that is currently locked
622 * Waits until this thread is woken up on @cond. The @mutex is unlocked
623 * before falling asleep and locked again before resuming.
625 * This function can be used even if g_thread_init() has not yet been
626 * called, and, in that case, will immediately return.
629 g_cond_wait (GCond *cond,
634 if G_UNLIKELY ((status = pthread_cond_wait (&cond->impl, &mutex->impl)) != 0)
635 g_thread_abort (status, "pthread_cond_wait");
642 * If threads are waiting for @cond, at least one of them is unblocked.
643 * If no threads are waiting for @cond, this function has no effect.
644 * It is good practice to hold the same lock as the waiting thread
645 * while calling this function, though not required.
647 * This function can be used even if g_thread_init() has not yet been
648 * called, and, in that case, will do nothing.
651 g_cond_signal (GCond *cond)
655 if G_UNLIKELY ((status = pthread_cond_signal (&cond->impl)) != 0)
656 g_thread_abort (status, "pthread_cond_signal");
663 * If threads are waiting for @cond, all of them are unblocked.
664 * If no threads are waiting for @cond, this function has no effect.
665 * It is good practice to lock the same mutex as the waiting threads
666 * while calling this function, though not required.
668 * This function can be used even if g_thread_init() has not yet been
669 * called, and, in that case, will do nothing.
672 g_cond_broadcast (GCond *cond)
676 if G_UNLIKELY ((status = pthread_cond_broadcast (&cond->impl)) != 0)
677 g_thread_abort (status, "pthread_cond_broadcast");
683 * @mutex: a #GMutex that is currently locked
684 * @abs_time: a #GTimeVal, determining the final time
686 * Waits until this thread is woken up on @cond, but not longer than
687 * until the time specified by @abs_time. The @mutex is unlocked before
688 * falling asleep and locked again before resuming.
690 * If @abs_time is %NULL, g_cond_timed_wait() acts like g_cond_wait().
692 * This function can be used even if g_thread_init() has not yet been
693 * called, and, in that case, will immediately return %TRUE.
695 * To easily calculate @abs_time a combination of g_get_current_time()
696 * and g_time_val_add() can be used.
698 * Returns: %TRUE if @cond was signalled, or %FALSE on timeout
701 g_cond_timed_wait (GCond *cond,
705 struct timespec end_time;
708 if (abs_time == NULL)
710 g_cond_wait (cond, mutex);
714 end_time.tv_sec = abs_time->tv_sec;
715 end_time.tv_nsec = abs_time->tv_usec * 1000;
717 if ((status = pthread_cond_timedwait (&cond->impl, &mutex->impl, &end_time)) == 0)
720 if G_UNLIKELY (status != ETIMEDOUT)
721 g_thread_abort (status, "pthread_cond_timedwait");
729 * @mutex: a #GMutex that is currently locked
730 * @abs_time: the final time, in microseconds
732 * A variant of g_cond_timed_wait() that takes @abs_time
733 * as a #gint64 instead of a #GTimeVal.
734 * See g_cond_timed_wait() for details.
736 * Returns: %TRUE if @cond was signalled, or %FALSE on timeout
741 g_cond_timedwait (GCond *cond,
745 struct timespec end_time;
748 end_time.tv_sec = abs_time / 1000000;
749 end_time.tv_nsec = (abs_time % 1000000) * 1000;
751 if ((status = pthread_cond_timedwait (&cond->impl, &mutex->impl, &end_time)) == 0)
754 if G_UNLIKELY (status != ETIMEDOUT)
755 g_thread_abort (status, "pthread_cond_timedwait");
765 * The #GPrivate struct is an opaque data structure to represent a
766 * thread-local data key. It is approximately equivalent to the
767 * <function>pthread_setspecific()</function>/<function>pthread_getspecific()</function>
768 * APIs on POSIX and to
769 * <function>TlsSetValue()</function>/<function>TlsGetValue<()/function> on
772 * If you don't already know why you might want this functionality, then
773 * you probably don't need it.
775 * #GPrivate is a very limited resource (as far as 128 per program,
776 * shared between all libraries). It is also not possible to destroy a
777 * #GPrivate after it has been used. As such, it is only ever acceptable
778 * to use #GPrivate in static scope, and even then sparingly so.
780 * See G_PRIVATE_INIT() for a couple of examples.
782 * The #GPrivate structure should be considered opaque. It should only
783 * be accessed via the <function>g_private_</function> functions.
788 * @notify: a #GDestroyNotify
790 * A macro to assist with the static initialisation of a #GPrivate.
792 * This macro is useful for the case that a #GDestroyNotify function
793 * should be associated the key. This is needed when the key will be
794 * used to point at memory that should be deallocated when the thread
797 * Additionally, the #GDestroyNotify will also be called on the previous
798 * value stored in the key when g_private_replace() is used.
800 * If no #GDestroyNotify is needed, then use of this macro is not
801 * required -- if the #GPrivate is declared in static scope then it will
802 * be properly initialised by default (ie: to all zeros). See the
806 * static GPrivate name_key = G_PRIVATE_INIT (g_free);
808 * // return value should not be freed
810 * get_local_name (void)
812 * return g_private_get (&name_key);
816 * set_local_name (const gchar *name)
818 * g_private_replace (&name_key, g_strdup (name));
822 * static GPrivate count_key; // no free function
825 * get_local_count (void)
827 * return GPOINTER_TO_INT (g_private_get (&count_key));
831 * set_local_count (gint count)
833 * g_private_set (&count_key, GINT_TO_POINTER (count));
840 static pthread_key_t *
841 g_private_impl_new (GDestroyNotify notify)
846 key = malloc (sizeof (pthread_key_t));
847 if G_UNLIKELY (key == NULL)
848 g_thread_abort (errno, "malloc");
849 status = pthread_key_create (key, notify);
850 if G_UNLIKELY (status != 0)
851 g_thread_abort (status, "pthread_key_create");
857 g_private_impl_free (pthread_key_t *key)
861 status = pthread_key_delete (*key);
862 if G_UNLIKELY (status != 0)
863 g_thread_abort (status, "pthread_key_delete");
867 static pthread_key_t *
868 g_private_get_impl (GPrivate *key)
870 pthread_key_t *impl = key->p;
872 if G_UNLIKELY (impl == NULL)
874 impl = g_private_impl_new (key->notify);
875 if (!g_atomic_pointer_compare_and_exchange (&key->p, NULL, impl))
877 g_private_impl_free (impl);
889 * Returns the current value of the thread local variable @key.
891 * If the value has not yet been set in this thread, %NULL is returned.
892 * Values are never copied between threads (when a new thread is
893 * created, for example).
895 * Returns: the thread-local value
898 g_private_get (GPrivate *key)
900 /* quote POSIX: No errors are returned from pthread_getspecific(). */
901 return pthread_getspecific (*g_private_get_impl (key));
907 * @value: the new value
909 * Sets the thread local variable @key to have the value @value in the
912 * This function differs from g_private_replace() in the following way:
913 * the #GDestroyNotify for @key is not called on the old value.
916 g_private_set (GPrivate *key,
921 if G_UNLIKELY ((status = pthread_setspecific (*g_private_get_impl (key), value)) != 0)
922 g_thread_abort (status, "pthread_setspecific");
928 * @value: the new value
930 * Sets the thread local variable @key to have the value @value in the
933 * This function differs from g_private_set() in the following way: if
934 * the previous value was non-%NULL then the #GDestroyNotify handler for
940 g_private_replace (GPrivate *key,
943 pthread_key_t *impl = g_private_get_impl (key);
947 old = pthread_getspecific (*impl);
948 if (old && key->notify)
951 if G_UNLIKELY ((status = pthread_setspecific (*impl, value)) != 0)
952 g_thread_abort (status, "pthread_setspecific");
957 #define posix_check_err(err, name) G_STMT_START{ \
960 g_error ("file %s: line %d (%s): error '%s' during '%s'", \
961 __FILE__, __LINE__, G_STRFUNC, \
962 g_strerror (error), name); \
965 #define posix_check_cmd(cmd) posix_check_err (cmd, #cmd)
968 g_system_thread_create (GThreadFunc thread_func,
978 g_return_if_fail (thread_func);
980 posix_check_cmd (pthread_attr_init (&attr));
982 #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
985 #ifdef _SC_THREAD_STACK_MIN
986 stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), stack_size);
987 #endif /* _SC_THREAD_STACK_MIN */
988 /* No error check here, because some systems can't do it and
989 * we simply don't want threads to fail because of that. */
990 pthread_attr_setstacksize (&attr, stack_size);
992 #endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
994 posix_check_cmd (pthread_attr_setdetachstate (&attr,
995 joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
997 ret = pthread_create (thread, &attr, (void* (*)(void*))thread_func, arg);
999 posix_check_cmd (pthread_attr_destroy (&attr));
1003 g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
1004 "Error creating thread: %s", g_strerror (ret));
1008 posix_check_err (ret, "pthread_create");
1014 * Gives way to other threads waiting to be scheduled.
1016 * This function is often used as a method to make busy wait less evil.
1017 * But in most cases you will encounter, there are better methods to do
1018 * that. So in general you shouldn't use this function.
1021 g_thread_yield (void)
1027 g_system_thread_join (gpointer thread)
1030 posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore));
1034 g_system_thread_exit (void)
1036 pthread_exit (NULL);
1040 g_system_thread_self (gpointer thread)
1042 *(pthread_t*)thread = pthread_self();
1046 g_system_thread_equal (gpointer thread1,
1049 return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
1053 g_system_thread_set_name (const gchar *name)
1055 #ifdef HAVE_SYS_PRCTL_H
1056 prctl (PR_SET_NAME, name, 0, 0, 0, 0);
1061 /* vim:set foldmethod=marker: */