diff --git a/camel/camel-net-utils.c b/camel/camel-net-utils.c
index d447e41..49324cf 100644
--- a/camel/camel-net-utils.c
+++ b/camel/camel-net-utils.c
@@ -26,7 +26,6 @@
 #endif
 
 #include <errno.h>
-#include <pthread.h>
 #include <stdio.h>
 
 #include <glib.h>
@@ -447,8 +446,9 @@ static gint
 cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar *error, CamelException *ex)
 {
 	CamelMsgPort *reply_port;
-	pthread_t id;
-	gint err, cancel_fd, cancel = 0, fd;
+	GThread *thread;
+	GError *err = NULL;
+	gint cancel_fd, cancel = 0, fd;
 
 	cancel_fd = camel_operation_cancel_fd(NULL);
 	if (cancel_fd == -1) {
@@ -458,7 +458,7 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 
 	reply_port = msg->msg.reply_port = camel_msgport_new();
 	fd = camel_msgport_fd(msg->msg.reply_port);
-	if ((err = pthread_create(&id, NULL, worker, msg)) == 0) {
+	if ((thread = g_thread_create (worker, msg, TRUE, &err)) != NULL) {
 		gint status;
 #ifndef G_OS_WIN32
 		GPollFD polls[2];
@@ -506,19 +506,23 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 			   We check the reply port incase we had a reply in the mean time, which we free later */
 			d(printf("Canceling lookup thread and leaving it\n"));
 			msg->cancelled = 1;
-			pthread_cancel(id);
-			pthread_join (id, NULL);
+			g_thread_join (thread);
 			cancel = 1;
 		} else {
-			struct _addrinfo_msg *reply = (struct _addrinfo_msg *)camel_msgport_try_pop(reply_port);
+			struct _addrinfo_msg *reply;
 
-			g_assert(reply == msg);
 			d(printf("waiting for child to exit\n"));
-			pthread_join(id, NULL);
+			g_thread_join (thread);
 			d(printf("child done\n"));
+
+			reply = (struct _addrinfo_msg *)camel_msgport_try_pop(reply_port);
+			if (reply != msg)
+				g_warning ("%s: Received msg reply %p doesn't match msg %p", G_STRFUNC, reply, msg);
 		}
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), g_strerror(err));
+		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), err ? err->message : _("Unknown error"));
+		if (err)
+			g_error_free (err);
 	}
 	camel_msgport_destroy(reply_port);
 
@@ -540,13 +544,12 @@ cs_getaddrinfo(gpointer data)
 	/* This is a pretty simplistic emulation of getaddrinfo */
 
 	while ((msg->result = camel_gethostbyname_r(msg->name, &h, msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
-		pthread_testcancel();
+		if (msg->cancelled)
+			break;
                 msg->hostbuflen *= 2;
                 msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
 	}
 
-	pthread_testcancel ();
-
 	/* If we got cancelled, dont reply, just free it */
 	if (msg->cancelled)
 		goto cancel;
@@ -599,9 +602,7 @@ cs_getaddrinfo(gpointer data)
 		}
 	}
 
-	pthread_testcancel ();
-
-	for (i=0;h.h_addr_list[i];i++) {
+	for (i = 0; h.h_addr_list[i] && !msg->cancelled; i++) {
 		res = g_malloc0(sizeof(*res));
 		if (msg->hints) {
 			res->ai_flags = msg->hints->ai_flags;
@@ -651,8 +652,6 @@ cs_getaddrinfo(gpointer data)
 			info->result = getaddrinfo(info->name, "443", info->hints, info->res);
 	}
 
-	pthread_testcancel ();
-
 	if (!info->cancelled)
 		camel_msgport_reply((CamelMsg *)info);
 
@@ -747,7 +746,8 @@ cs_getnameinfo(gpointer data)
 
 	while ((msg->result = camel_gethostbyaddr_r((const gchar *)&sin->sin_addr, sizeof(sin->sin_addr), AF_INET, &h,
 						    msg->hostbufmem, msg->hostbuflen, &herr)) == ERANGE) {
-		pthread_testcancel ();
+		if (msg->cancelled)
+			break;
                 msg->hostbuflen *= 2;
                 msg->hostbufmem = g_realloc(msg->hostbufmem, msg->hostbuflen);
 	}
@@ -755,8 +755,6 @@ cs_getnameinfo(gpointer data)
 	if (msg->cancelled)
 		goto cancel;
 
-	pthread_testcancel ();
-
 	if (msg->host) {
 		g_free(msg->host);
 		if (msg->result == 0 && h.h_name && h.h_name[0]) {
@@ -773,7 +771,8 @@ cs_getnameinfo(gpointer data)
 	if (msg->serv)
 		sprintf(msg->serv, "%d", sin->sin_port);
 
-	camel_msgport_reply((CamelMsg *)msg);
+	if (!msg->cancelled)
+		camel_msgport_reply ((CamelMsg *)msg);
 cancel:
 	return NULL;
 }
@@ -786,8 +785,6 @@ cs_getnameinfo(gpointer data)
 	/* there doens't appear to be a return code which says host or serv buffers are too short, lengthen them */
 	msg->result = getnameinfo(msg->addr, msg->addrlen, msg->host, msg->hostlen, msg->serv, msg->servlen, msg->flags);
 
-	pthread_testcancel ();
-
 	if (!msg->cancelled)
 		camel_msgport_reply((CamelMsg *)msg);
 
