From d5f0cec440ef2848992ce0ae34bfe73bb0c9772a Mon Sep 17 00:00:00 2001
From: Sylvain Munaut <246tnt@gmail.com>
Date: Sun, 13 Oct 2013 17:19:37 -0700
Subject: wxgui: Allow Linux/X11 apps to be thread-safe

Call XInitThreads as first Xlib call
---
 gr-wxgui/python/wxgui/stdgui2.py | 9 +++++++++
 1 file changed, 9 insertions(+)

(limited to 'gr-wxgui/python/wxgui/stdgui2.py')

diff --git a/gr-wxgui/python/wxgui/stdgui2.py b/gr-wxgui/python/wxgui/stdgui2.py
index 71436d72c4..b38589988e 100644
--- a/gr-wxgui/python/wxgui/stdgui2.py
+++ b/gr-wxgui/python/wxgui/stdgui2.py
@@ -21,6 +21,8 @@
 
 '''A simple wx gui for GNU Radio applications'''
 
+import ctypes
+import os
 import wx
 import sys
 from gnuradio import gr
@@ -33,6 +35,13 @@ class stdapp (wx.App):
         self.title = title
         self._nstatus = nstatus
         self._max_noutput_items = max_noutput_items
+        # If we're on Linux, also enable multi-threading Xlib access
+        if os.name == 'posix':
+            try:
+                x11 = ctypes.cdll.LoadLibrary('libX11.so')
+                x11.XInitThreads()
+            except:
+                print "Warning: failed to XInitThreads()"
         # All our initialization must come before calling wx.App.__init__.
         # OnInit is called from somewhere in the guts of __init__.
         wx.App.__init__ (self, redirect=False)
-- 
cgit v1.2.3