mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-24 03:02:10 +01:00
Updated the documentation to explain that when the maximum threads is > 1
* glib/gthreadpool.c: Updated the documentation to explain that when the maximum threads is > 1 the sort functionality is not 100% accurate due to the ramdom nature of the scheduler choosing which threads to execute. Fixes bug #334943. * tests/threadpool-test.c: Disabled the debugging by default and fixed the sort test to set the maximum threads to 1 to guarantee the thread entry function is called in order.
This commit is contained in:
parent
0028b643bc
commit
21b05cd677
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
|||||||
|
2006-03-24 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
|
* glib/gthreadpool.c: Updated the documentation to explain that
|
||||||
|
when the maximum threads is > 1 the sort functionality is not 100%
|
||||||
|
accurate due to the ramdom nature of the scheduler choosing which
|
||||||
|
threads to execute. Fixes bug #334943.
|
||||||
|
|
||||||
|
* tests/threadpool-test.c: Disabled the debugging by default and
|
||||||
|
fixed the sort test to set the maximum threads to 1 to guarantee
|
||||||
|
the thread entry function is called in order.
|
||||||
|
|
||||||
2006-03-20 Vladimer Sichinava <vlsichinava@gmail.com>
|
2006-03-20 Vladimer Sichinava <vlsichinava@gmail.com>
|
||||||
|
|
||||||
* configure.in: Added "ka" (Georgian) to ALL_LINGUAS
|
* configure.in: Added "ka" (Georgian) to ALL_LINGUAS
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2006-03-24 Martyn Russell <martyn@imendio.com>
|
||||||
|
|
||||||
|
* glib/gthreadpool.c: Updated the documentation to explain that
|
||||||
|
when the maximum threads is > 1 the sort functionality is not 100%
|
||||||
|
accurate due to the ramdom nature of the scheduler choosing which
|
||||||
|
threads to execute. Fixes bug #334943.
|
||||||
|
|
||||||
|
* tests/threadpool-test.c: Disabled the debugging by default and
|
||||||
|
fixed the sort test to set the maximum threads to 1 to guarantee
|
||||||
|
the thread entry function is called in order.
|
||||||
|
|
||||||
2006-03-20 Vladimer Sichinava <vlsichinava@gmail.com>
|
2006-03-20 Vladimer Sichinava <vlsichinava@gmail.com>
|
||||||
|
|
||||||
* configure.in: Added "ka" (Georgian) to ALL_LINGUAS
|
* configure.in: Added "ka" (Georgian) to ALL_LINGUAS
|
||||||
|
@ -817,6 +817,12 @@ g_thread_pool_stop_unused_threads (void)
|
|||||||
* tasks to be processed by a priority determined by @func, and not
|
* tasks to be processed by a priority determined by @func, and not
|
||||||
* just in the order in which they were added to the pool.
|
* just in the order in which they were added to the pool.
|
||||||
*
|
*
|
||||||
|
* Note, if the maximum number of threads is more than 1, the order
|
||||||
|
* that threads are executed can not be guranteed 100%. Threads are
|
||||||
|
* scheduled by the operating system and are executed at random. It
|
||||||
|
* cannot be assumed that threads are executed in the order they are
|
||||||
|
* created.
|
||||||
|
*
|
||||||
* Since: 2.10
|
* Since: 2.10
|
||||||
**/
|
**/
|
||||||
void
|
void
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
/* #define DEBUG_MSG(x) */
|
#define DEBUG_MSG(x)
|
||||||
#define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n");
|
/* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n"); */
|
||||||
|
|
||||||
#define RUNS 100
|
#define RUNS 100
|
||||||
|
|
||||||
@ -124,10 +124,11 @@ test_thread_sort_entry_func (gpointer data, gpointer user_data)
|
|||||||
g_assert (last_thread_id <= thread_id);
|
g_assert (last_thread_id <= thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here we remember one fail and if it concurrently fails, it
|
/* Here we remember one fail and if it concurrently fails, it
|
||||||
can not be sorted. the last thread id might be < this thread
|
* can not be sorted. the last thread id might be < this thread
|
||||||
id if something is added to the queue since threads were
|
* id if something is added to the queue since threads were
|
||||||
created */
|
* created
|
||||||
|
*/
|
||||||
last_failed = TRUE;
|
last_failed = TRUE;
|
||||||
} else {
|
} else {
|
||||||
last_failed = FALSE;
|
last_failed = FALSE;
|
||||||
@ -145,12 +146,29 @@ static void
|
|||||||
test_thread_sort (gboolean sort)
|
test_thread_sort (gboolean sort)
|
||||||
{
|
{
|
||||||
GThreadPool *pool;
|
GThreadPool *pool;
|
||||||
guint limit = 20;
|
guint limit;
|
||||||
|
guint max_threads;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
|
limit = MAX_THREADS * 10;
|
||||||
|
|
||||||
|
if (sort) {
|
||||||
|
max_threads = 1;
|
||||||
|
} else {
|
||||||
|
max_threads = MAX_THREADS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* It is important that we only have a maximum of 1 thread for this
|
||||||
|
* test since the results can not be guranteed to be sorted if > 1.
|
||||||
|
*
|
||||||
|
* Threads are scheduled by the operating system and are executed at
|
||||||
|
* random. It cannot be assumed that threads are executed in the
|
||||||
|
* order they are created. This was discussed in bug #334943.
|
||||||
|
*/
|
||||||
|
|
||||||
pool = g_thread_pool_new (test_thread_sort_entry_func,
|
pool = g_thread_pool_new (test_thread_sort_entry_func,
|
||||||
GINT_TO_POINTER (sort),
|
GINT_TO_POINTER (sort),
|
||||||
MAX_THREADS,
|
max_threads,
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
@ -165,10 +183,17 @@ test_thread_sort (gboolean sort)
|
|||||||
for (i = 0; i < limit; i++) {
|
for (i = 0; i < limit; i++) {
|
||||||
guint id;
|
guint id;
|
||||||
|
|
||||||
id = g_random_int_range (1, limit*2);
|
id = g_random_int_range (1, limit) + 1;
|
||||||
g_thread_pool_push (pool, GUINT_TO_POINTER (id + 1), NULL);
|
g_thread_pool_push (pool, GUINT_TO_POINTER (id), NULL);
|
||||||
|
DEBUG_MSG (("%s ===> pushed new thread with id:%d, number "
|
||||||
|
"of threads:%d, unprocessed:%d",
|
||||||
|
sort ? "[ sorted]" : "[unsorted]",
|
||||||
|
id,
|
||||||
|
g_thread_pool_get_num_threads (pool),
|
||||||
|
g_thread_pool_unprocessed (pool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_assert (g_thread_pool_get_max_threads (pool) == max_threads);
|
||||||
g_assert (g_thread_pool_get_num_threads (pool) == g_thread_pool_get_max_threads (pool));
|
g_assert (g_thread_pool_get_num_threads (pool) == g_thread_pool_get_max_threads (pool));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user