  
  	debug = getenv("WAYLAND_DEBUG");
  	if (debug)
-@@ -396,6 +417,21 @@ wl_display_connect(const char *name)
+@@ -397,6 +419,21 @@ wl_display_connect(const char *name)
  		return NULL;
  	}
  

 }
 
 static void
@@ -500,7 +576,11 @@ WL_EXPORT void
 wl_display_iterate(struct wl_display *display, uint32_t mask)
 {
 	uint32_t p[2], object, opcode, size;
+	uint64_t write_fd;
 	int len;
+	ssize_t success;
+
+	pthread_mutex_lock(&display->marshalling_mutex);
 
 	mask &= display->mask;
 	if (mask == 0) {
@@ -509,6 +589,23 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 		return;
 	}
 

 	len = wl_connection_data(display->connection, mask);
 
 	while (len > 0) {
@@ -528,6 +627,8 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 		len -= size;
 	}
 
