mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-10-28 23:12:17 +01:00
GThreadPool - Don't inherit thread priorities when creating new threads
By default (on POSIX) we would be inheriting thread priorities from the thread that pushed a new task on non-exclusive thread pools and causes a new thread to be created. This can cause any non-exclusive thread pool to accidentally contain threads of different priorities, or e.g. threads with real-time priority. To prevent this, custom handling for setting the scheduler settings for Linux and Windows is added and as a fallback for other platforms a new thread is added that is responsible for spawning threads for non-exclusive thread pools. Fixes https://gitlab.gnome.org/GNOME/glib/issues/1834
This commit is contained in:
@@ -853,7 +853,7 @@ g_thread_new (const gchar *name,
|
||||
GError *error = NULL;
|
||||
GThread *thread;
|
||||
|
||||
thread = g_thread_new_internal (name, g_thread_proxy, func, data, 0, &error);
|
||||
thread = g_thread_new_internal (name, g_thread_proxy, func, data, 0, NULL, &error);
|
||||
|
||||
if G_UNLIKELY (thread == NULL)
|
||||
g_error ("creating thread '%s': %s", name ? name : "", error->message);
|
||||
@@ -884,21 +884,29 @@ g_thread_try_new (const gchar *name,
|
||||
gpointer data,
|
||||
GError **error)
|
||||
{
|
||||
return g_thread_new_internal (name, g_thread_proxy, func, data, 0, error);
|
||||
return g_thread_new_internal (name, g_thread_proxy, func, data, 0, NULL, error);
|
||||
}
|
||||
|
||||
GThread *
|
||||
g_thread_new_internal (const gchar *name,
|
||||
GThreadFunc proxy,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gsize stack_size,
|
||||
GError **error)
|
||||
g_thread_new_internal (const gchar *name,
|
||||
GThreadFunc proxy,
|
||||
GThreadFunc func,
|
||||
gpointer data,
|
||||
gsize stack_size,
|
||||
const GThreadSchedulerSettings *scheduler_settings,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (func != NULL, NULL);
|
||||
|
||||
return (GThread*) g_system_thread_new (proxy, stack_size, name,
|
||||
func, data, error);
|
||||
return (GThread *) g_system_thread_new (proxy, stack_size, scheduler_settings,
|
||||
name, func, data, error);
|
||||
}
|
||||
|
||||
void
|
||||
g_thread_get_scheduler_settings (GThreadSchedulerSettings *scheduler_settings)
|
||||
{
|
||||
g_return_if_fail (scheduler_settings != NULL);
|
||||
g_system_thread_get_scheduler_settings (scheduler_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user