diff --git a/thread.c b/thread.c
index 0b52cbd..9e21f89 100644
--- a/thread.c
+++ b/thread.c
@@ -4903,6 +4903,29 @@ rb_thread_backtrace_locations_m(int argc, VALUE *argv, VALUE thval)
     return rb_vm_thread_backtrace_locations(argc, argv, thval);
 }
 
+static void *
+xmtest(void *ptr)
+{
+    size_t *size = ptr;
+
+    xfree(xmalloc(*size));
+    return 0;
+}
+
+static VALUE
+test_xmalloc(VALUE self, VALUE n)
+{
+    size_t size = NUM2SIZET(n);
+    pthread_t th;
+    int rc = pthread_create(&th, 0, xmtest, &size);
+    if (rc != 0) rb_bug("pthread_create failed: %d", rc);
+
+    rc = pthread_join(th, 0);
+    if (rc != 0) rb_bug("pthread_join failed: %d", rc);
+
+    return Qnil;
+}
+
 /*
  *  Document-class: ThreadError
  *
@@ -4950,6 +4973,7 @@ Init_Thread(void)
 #endif
     rb_define_singleton_method(rb_cThread, "handle_interrupt", rb_thread_s_handle_interrupt, 1);
     rb_define_singleton_method(rb_cThread, "pending_interrupt?", rb_thread_s_pending_interrupt_p, -1);
+    rb_define_singleton_method(rb_cThread, "test_xmalloc", test_xmalloc, 1);
     rb_define_method(rb_cThread, "pending_interrupt?", rb_thread_pending_interrupt_p, -1);
 
     rb_define_method(rb_cThread, "initialize", thread_initialize, -2);
