
#include <glib-object.h>
#include <gio/gio.h>

// #define ENABLE_LOCK

#ifdef ENABLE_LOCK
#    define LOCK(X) g_static_mutex_lock (X)
#    define UNLOCK(X) g_static_mutex_unlock (X)
#else
#    define LOCK(X)
#    define UNLOCK(X)
#endif

static GObject *obj;

static void weak_notify1 (gpointer data, GObject *obj) { }
static void weak_notify2 (gpointer data, GObject *obj) { }

static gpointer
do_loop (gpointer notify)
{
  static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
  while (1)
    {
      LOCK (&mutex);
      g_object_weak_ref (obj, notify, NULL);
      UNLOCK (&mutex);

      LOCK (&mutex);
      g_object_weak_unref (obj, notify, NULL);
      UNLOCK (&mutex);
    }
}

int
main (void)
{
  g_type_init ();
  g_thread_init (NULL);

  obj = G_OBJECT (g_file_info_new ());

  g_thread_create (do_loop, weak_notify1, FALSE, NULL);
  do_loop (weak_notify2);

  return 0;
}
