TkButton#command problem with threads

  • Thread starter Henrik Steensland
  • Start date
H

Henrik Steensland

I upgraded to FreeBSD's latest version of ruby.
ruby 1.8.1 (2004-05-02) [i386-freebsd5]

Now, some of my Ruby/Tk applications won't work anymore.
The problem seems to be this.

cmd = proc{
puts "a"
Thread.new{
sleep 10
}
puts "b"
}

TkButton.new{
text "Push"
command cmd
pack
}

When running cmd.call i get the printout "a" and "b" quickly. The new Thread
is just sleeping quietly in the background.
However, when I push my TkButton, I get the "a", then the whole program
sleeps for 10 seconds, then I get the "b". So something is really strange
here. I had no problems with the code above in earlier versions.
 
H

Hidetoshi NAGAI

Hi,

From: "Henrik Steensland" <[email protected]>
Subject: TkButton#command problem with threads
Date: Fri, 4 Jun 2004 08:17:27 +0900
Message-ID: said:
When running cmd.call i get the printout "a" and "b" quickly. The new Thread
is just sleeping quietly in the background.
However, when I push my TkButton, I get the "a", then the whole program
sleeps for 10 seconds, then I get the "b". So something is really strange
here. I had no problems with the code above in earlier versions.

Thank you for your report. Please test the following patch.

--- tcltklib.c.old 2004-06-04 10:15:14.000000000 +0900
+++ tcltklib.c 2004-06-04 10:16:17.000000000 +0900
@@ -1008,7 +1008,9 @@
(VALUE)0);
#else

+ rb_thread_critical = Qfalse;
ret = rb_eval_string_protect(arg->string, &status);
+ rb_thread_critical = Qtrue;
if (status) {
char *errtype, *buf;
int errtype_len, len;
@@ -1288,9 +1290,13 @@
struct cmd_body_arg *arg;
{
VALUE ret;
+ int thr_crit_bup;

DUMP1("call ip_ruby_cmd_core");
+ thr_crit_bup = rb_thread_critical;
+ rb_thread_critical = Qfalse;
ret = rb_apply(arg->receiver, arg->method, arg->args);
+ rb_thread_critical = thr_crit_bup;
DUMP1("finish ip_ruby_cmd_core");

return ret;
 
H

Henrik Steensland

Thank you very much for your patch.
Now it works nicely.
-----Original Message-----
From: Hidetoshi NAGAI [mailto:[email protected]]
Sent: Friday, June 04, 2004 3:20 AM
To: ruby-talk ML
Subject: Re: TkButton#command problem with threads

Hi,

From: "Henrik Steensland" <[email protected]>
Subject: TkButton#command problem with threads
Date: Fri, 4 Jun 2004 08:17:27 +0900
Message-ID: said:
When running cmd.call i get the printout "a" and "b" quickly. The new
Thread is just sleeping quietly in the background.
However, when I push my TkButton, I get the "a", then the whole
program sleeps for 10 seconds, then I get the "b". So something is
really strange here. I had no problems with the code above
in earlier versions.

Thank you for your report. Please test the following patch.
>
--- tcltklib.c.old 2004-06-04 10:15:14.000000000 +0900
+++ tcltklib.c 2004-06-04 10:16:17.000000000 +0900
@@ -1008,7 +1008,9 @@
(VALUE)0);
#else

+ rb_thread_critical = Qfalse;
ret = rb_eval_string_protect(arg->string, &status);
+ rb_thread_critical = Qtrue;
if (status) {
char *errtype, *buf;
int errtype_len, len;
@@ -1288,9 +1290,13 @@
struct cmd_body_arg *arg;
{
VALUE ret;
+ int thr_crit_bup;

DUMP1("call ip_ruby_cmd_core");
+ thr_crit_bup = rb_thread_critical;
+ rb_thread_critical = Qfalse;
ret = rb_apply(arg->receiver, arg->method, arg->args);
+ rb_thread_critical = thr_crit_bup;
DUMP1("finish ip_ruby_cmd_core");

return ret;
>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top