# Re: hang on leopard

**URL:** <https://www.ruby-forum.com/t/re-hang-on-leopard/129865>\
**Category:** wxRuby\
**Created:** [February 22, 2008, 5:09am UTC](https://www.ruby-forum.com/t/re-hang-on-leopard/129865 "2008-02-22T05:09:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhang\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/cdc98d/32.png) [@Zhang\_P](https://www.ruby-forum.com/u/Zhang_P)\
**Post date:** [February 22, 2008, 5:09am UTC](https://www.ruby-forum.com/t/re-hang-on-leopard/129865/1 "2008-02-22T05:09:17Z")

</div>

Hi Mario,

Alex and you are great !

I’ll try not to bother you guys too much 🙂 🙂 🙂

I’m going to restructure my program and not use ruby threads in WxDialog  
based class, and use WxEvent instead per Alex’s suggestion.

I’m sure you guys will have a chance to help me out again in the near  
future 🙂 🙂 🙂

Sincerely … Z.P.

----- Original Message ----  
From: Mario S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: General discussion of wxRuby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, February 21, 2008 8:14:51 PM  
Subject: Re: [wxruby-users] hang on leopard

Hey Zhang,

No problem. If you need help re-structuring the layout of your program,  
feel free to email me, and I’ll be happy to help you out with it.

Good Luck,

Mario S.

On 2/21/08, Zhang P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi Mario,

Thanks for the explanation. I appreciate it.

The _only_ reason I was trying out scripting language is because of the  
“cross platform” (write once and use everywhere).

I’m going to give another try of _not_ using thread and use WxEvent per  
Alex’s suggestion and see what happens.

If it still give the same issues, then I guess I have to rethink my  
strategy …

Thanks again for the feedback.

----- Original Message ----  
From: Mario S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

To: General discussion of wxRuby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Wednesday, February 20, 2008 7:52:48 PM

Subject: Re: [wxruby-users] hang on leopard

Hello Zhang,

As much as we even would like that to be true, the problem is, there is  
a difference between all three platforms. On Windows, we use Microsoft  
Visual C++ Compiler to compile wxRuby, as that is the most common  
compiler used for Ruby. On Linux, we use GCC, as that is the general  
one. And on Mac OS X, we use Cocoa for the most part, and some GCC.  
Now with these three different compilers, each is oviously creating a  
different executable, where certian features are not going to be  
available. So while, say on Linux and Windows, we could possibly use  
Threads to work with the GUI Components of wxRuby, on Mac, that may not  
be the case. On Mac and on Linux, there are certian classes not  
available, just like on Windows.

Cause of all of this, there are bound to be problems on certian  
platforms, where they wouldn’t arise on others. I’ve ran into this kind  
of deal, working with various projects between just Windows and Linux,  
but it can be worse if adding in Mac OS X.

Just cause your doing the same thing as far as code goes between  
different platforms, the actual backends are doing completely different  
things, to get things to work the way you want them to.

L8ers,

Mario S.

On 2/20/08, Zhang P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Thanks for the explanation, Alex.

If it is a thread issue, I wonder why I couldn’t duplicate it on XP?  
Since I can’t duplicate it on XP, I was thinking that it is not just a  
pure thread issue, but Wx for OSX + ruby thread combination is the  
culprit. If it is a pure thread issue, I would think that I should had  
hit it on XP too since I did an extensive testing on XP without seeing  
any problem, unless I was really lucky to not hit the thread bug on XP.

I’m already using Mutex for shared variables.

Thanks for offering help on design choice. I appreciate it !

I don’t actually have a lot of globals and threads … only 2 globals  
and 3 threads. Let me try to explain:

I have one dialog box that shows a number flashing on the screen one  
after another, and another dialog box that shows the time and a input  
text field to collect the answer the user types in for adding up all  
those numbers from the other dialog.

So, I have 2 global variables: one for each instance of the dialog box.  
I use global because I do not want to destroy and create a new instance  
of the dialog box every time a user want to do the exercise.

I have 3 threads: one to show the flashing number, one to collect  
answer, and one for showing the time. I use WxTimer.every() for the  
timer per your suggestion. I use ruby thread for the other 2 as you see  
in the code I posted yesterday.

So, when user hit the button, both ruby threads will start/resume their  
tasks: one to show the number and one to collect the answer, and WxTimer  
shows the time.

If I can put the show(true/false) pair within the ruby threads, I do not  
need to create another WxTimer threads on my main thread to check when  
to “hide” the dialog box.

Thanks!

----- Original Message ----  
From: Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

To: General discussion of wxRuby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Wednesday, February 20, 2008 3:13:54 PM

Subject: Re: [wxruby-users] hang on leopard

Zhang P. wrote:

> Finally, I got my code to work properly by not using the show(true)  
> and show(false) pair within a thread in the classes that subclass from

> Dialog. The symptoms I experienced if you put the show(true/false)  
> pair within a Thread, you get the following problems:  
> …
> 
> > From my testing, it surely looks like there is a problem with using

> Wx’s show(true/false) within ruby’s Thread.  
> Thanks for posting your code. I agree with your analysis … but …

The wxWidgets documentation and mailing list are clear that GUI calls in  
wxWidgets (C++), like show(), should be restricted to a single thread

only. Now, ruby 1.8 threads are not the same as OS threads in wxWidgets,  
but some of the issues may be the same. In particular, the error message  
that you are getting sounds like OS X is complaining that execution is

being prematurely switched out of some core operation. That sounds to me  
like a possible thread problem.

> But hopefully you can see something else that I might had done wrong,  
> because it is much easier for me to fix my code

I think it is a primarily a design problem. You have a lot of globals,  
and a lot of Threads. In general, if you have a background task running  
in a ruby thread, notifications about the status of that thread’s work

should be handled either by a properly shared variable (using Mutex if  
needed), or by posting a Wx::Event from the slave thread to the master  
GUI thread.

If you were able to say a bit more about why you are using these

Threads, we’d be happy to be more specific about a safer alternative.

alex

* * *

wxruby-users mailing list  
removed\_email\_address@domain.invalid

[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Never miss a thing. Make Yahoo your homepage.

* * *

wxruby-users mailing list  
removed\_email\_address@domain.invalid

[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

–  
Mario S.  
[http://www.trilake.net](http://www.trilake.net)  
[http://www.ruby-im.net](http://www.ruby-im.net)

[http://rubyforge.org/projects/wxruby/](http://rubyforge.org/projects/wxruby/)  
[http://rubyforge.org/projects/wxride/](http://rubyforge.org/projects/wxride/)

[http://rubyforge.org/projects/vwmc/](http://rubyforge.org/projects/vwmc/)

-----Inline Attachment Follows-----

* * *

wxruby-users mailing list  
removed\_email\_address@domain.invalid

[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try  
it now.

* * *

wxruby-users mailing list  
removed\_email\_address@domain.invalid  
[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

–  
Mario S.  
[http://www.trilake.net](http://www.trilake.net)  
[http://www.ruby-im.net](http://www.ruby-im.net)  
[http://rubyforge.org/projects/wxruby/](http://rubyforge.org/projects/wxruby/)

[http://rubyforge.org/projects/wxride/](http://rubyforge.org/projects/wxride/)  
[http://rubyforge.org/projects/vwmc/](http://rubyforge.org/projects/vwmc/)

-----Inline Attachment Follows-----

* * *

wxruby-users  
mailing  
list  
removed\_email\_address@domain.invalid  
[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

```
  ____________________________________________________________________________________

```

Be a better friend, newshound, and  
know-it-all with Yahoo! Mobile. Try it now.  
[http://mobile.yahoo.com/;\_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ](http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ)
