2 #include <string.h> /* strerror */
4 #define MAX_THREADS 100
6 static GMemChunk *_chunks;
9 static gint num_allocs;
10 static gint num_threads;
17 ret = g_mem_chunk_alloc (_chunks);
18 g_mutex_unlock (_lock);
24 free_chunk (gpointer chunk)
27 g_mem_chunk_free (_chunks, chunk);
28 g_mutex_unlock (_lock);
33 run_test (void *threadid)
39 for (i = 0; i<num_allocs; i++) {
40 chunk = alloc_chunk ();
50 main (gint argc, gchar *argv[])
52 GThread *threads[MAX_THREADS];
56 gst_init (&argc, &argv);
59 g_print ("usage: %s <num_threads> <num_allocs>\n", argv[0]);
63 num_threads = atoi (argv[1]);
64 num_allocs = atoi (argv[2]);
66 _chunks = g_mem_chunk_new ("test", 32, 32 * 16, G_ALLOC_AND_FREE);
67 _lock = g_mutex_new ();
69 for(t=0; t < num_threads; t++) {
71 threads[t] = g_thread_create (run_test, GINT_TO_POINTER(t), TRUE, &error);
73 printf ("ERROR: g_thread_create () is %s\n", error->message);
77 printf ("main(): Created %d threads.\n", t);