diff --git a/configure b/configure
index 0c67a4a..a25e65c 100755
--- a/configure
+++ b/configure
@@ -1843,15 +1843,32 @@ EOF
 fi

 ##########################################
+# check if we have makecontext
+
+ucontext_coroutine=no
+if test "$darwin" != "yes"; then
+  cat > $TMPC << EOF
+#include <ucontext.h>
+int main(void) { makecontext(0, 0, 0); }
+EOF
+  if compile_prog "" "" ; then
+      ucontext_coroutine=yes
+  fi
+fi
+
+##########################################
 # glib support probe
-if test "$guest_agent" != "no" ; then
+if test "$guest_agent" != "no" -o "$ucontext_coroutine" != "yes" -a
"$mingw32" != "yes"; then
     if $pkg_config --modversion glib-2.0 > /dev/null 2>&1 ; then
         glib_cflags=`$pkg_config --cflags glib-2.0 2>/dev/null`
         glib_libs=`$pkg_config --libs glib-2.0 2>/dev/null`
-        libs_softmmu="$glib_libs $libs_softmmu"
-        libs_tools="$glib_libs $libs_tools"
+        gthread_cflags=`$pkg_config --cflags gthread-2.0 2>/dev/null`
+        gthread_libs=`$pkg_config --libs gthread-2.0 2>/dev/null`
+        glib_cflags="$glib_cflags $gthread_cflags"
+        libs_softmmu="$glib_libs $gthread_libs $libs_softmmu"
+        libs_tools="$glib_libs $gthread_libs $libs_tools"
     else
-        echo "glib-2.0 required to compile QEMU"
+        echo "glib-2.0 required to compile QEMU with guest agent or
gthread based coroutines"
         exit 1
