From 56c6afd03cd739f02bc5012920d74ac06ae92ae3 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 23 Jan 2015 11:04:40 +0100 Subject: Fix race condition with XOpenIM --- src/x11/window/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/x11') diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs index f4c296a..838a698 100644 --- a/src/x11/window/mod.rs +++ b/src/x11/window/mod.rs @@ -8,6 +8,7 @@ use std::sync::atomic::AtomicBool; use std::collections::RingBuf; use super::ffi; use std::sync::{Arc, Once, ONCE_INIT}; +use std::sync::{StaticMutex, MUTEX_INIT}; pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor}; @@ -262,6 +263,10 @@ impl Window { // creating IM let im = unsafe { + // XOpenIM doesn't seem to be thread-safe + static GLOBAL_XOPENIM_LOCK: StaticMutex = MUTEX_INIT; + let _lock = GLOBAL_XOPENIM_LOCK.lock().unwrap(); + let im = ffi::XOpenIM(display, ptr::null(), ptr::null_mut(), ptr::null_mut()); if im.is_null() { return Err(OsError(format!("XOpenIM failed"))); -- cgit v1.2.3