mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-01 13:23:07 +02:00
Check for "our" threads in some places
Don't allow g_thread_join() to be called on or g_thread_exit() to be called from within threads that were not created by GLib. Document this.
This commit is contained in:
parent
11f3684b71
commit
3fe3fdd75a
@ -849,14 +849,21 @@ g_thread_new_internal (const gchar *name,
|
|||||||
* Calling <literal>g_thread_exit (retval)</literal> is equivalent to
|
* Calling <literal>g_thread_exit (retval)</literal> is equivalent to
|
||||||
* returning @retval from the function @func, as given to g_thread_new().
|
* returning @retval from the function @func, as given to g_thread_new().
|
||||||
*
|
*
|
||||||
* <note><para>Never call g_thread_exit() from within a thread of a
|
* <note><para>
|
||||||
* #GThreadPool, as that will mess up the bookkeeping and lead to funny
|
* You must only call g_thread_exit() from a thread that you created
|
||||||
* and unwanted results.</para></note>
|
* yourself with g_thread_new() or related APIs. You must not call
|
||||||
|
* this function from a thread created with another threading library
|
||||||
|
* or or from within a #GThreadPool.
|
||||||
|
* </para></note>
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
g_thread_exit (gpointer retval)
|
g_thread_exit (gpointer retval)
|
||||||
{
|
{
|
||||||
GRealThread* real = (GRealThread*) g_thread_self ();
|
GRealThread* real = (GRealThread*) g_thread_self ();
|
||||||
|
|
||||||
|
if G_UNLIKELY (!real->ours)
|
||||||
|
g_error ("attempt to g_thread_exit() a thread not created by GLib");
|
||||||
|
|
||||||
real->retval = retval;
|
real->retval = retval;
|
||||||
|
|
||||||
g_system_thread_exit ();
|
g_system_thread_exit ();
|
||||||
@ -890,6 +897,7 @@ g_thread_join (GThread *thread)
|
|||||||
gpointer retval;
|
gpointer retval;
|
||||||
|
|
||||||
g_return_val_if_fail (thread, NULL);
|
g_return_val_if_fail (thread, NULL);
|
||||||
|
g_return_val_if_fail (real->ours, NULL);
|
||||||
|
|
||||||
g_system_thread_wait (real);
|
g_system_thread_wait (real);
|
||||||
|
|
||||||
@ -910,6 +918,12 @@ g_thread_join (GThread *thread)
|
|||||||
* current thread. Note that this function does not increase
|
* current thread. Note that this function does not increase
|
||||||
* the reference count of the returned object.
|
* the reference count of the returned object.
|
||||||
*
|
*
|
||||||
|
* This function will return a #GThread even for threads that were not
|
||||||
|
* created by GLib (ie: those created by other threading APIs). This
|
||||||
|
* may be useful for thread identification purposes (ie: comparisons)
|
||||||
|
* but you must not use GLib functions (such as g_thread_join()) on
|
||||||
|
* these threads.
|
||||||
|
*
|
||||||
* Returns: the #GThread representing the current thread
|
* Returns: the #GThread representing the current thread
|
||||||
*/
|
*/
|
||||||
GThread*
|
GThread*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user