
#include <stdio.h>
#include <glib.h>
#include <glib-object.h>

gint thr_finished = 0;

static gpointer copy_func (gpointer data) { }
static void free_func (gpointer data) { }

static gpointer
register_boxed_types (gpointer data)
{
    int i;
    char name[10];
    for (i = 0; i < 3000; i++) {
        sprintf (name, "Boxed%d", i);
        g_boxed_type_register_static (name, copy_func, free_func);
    }
    g_atomic_int_set (&thr_finished, 1);
    return NULL;
}

static void
gstring_copy_loop (void)
{
    GString *str1 = g_string_new ("String");
    while (!g_atomic_int_get (&thr_finished)) {
        GString *str2 = g_boxed_copy (G_TYPE_GSTRING, str1);
        g_boxed_free (G_TYPE_GSTRING, str2);
    }
    g_string_free (str1, TRUE);
}

int
main (int argc, char **argv)
{
    g_type_init ();
    g_thread_init (NULL);
    g_thread_create (register_boxed_types, NULL, TRUE, NULL);
    gstring_copy_loop ();
    return 0;
}
