View previous topic :: View next topic |
Author |
Message |
barrett9h
Joined: 02 May 2005 Posts: 26 Location: Brazil
|
Posted: Wed Jun 15, 2005 5:14 am Post subject: threads |
|
|
Code: |
int thread()
{
int i = 0;
while(!wants_to_quit) {
synchronized {
label.setLabel(std.string.toString(i));
}
writefln("i=?d", i);
++i;
std.c.time.sleep(1);
}
return 0;
}
|
This simple thread code makes the app window stop responding after some time. I can use it for a little while, while watching the label change, and soon it stops responding at all, it not even redraws on an expose. The thread continues to run, tough, as it continue to print on stdout. Then I have to ctrl-C on the console to stop it and close the stalled window.
Does (dyn)DUI plays nice with threads?
Am I doing something wrong?
Does the 'synchronized' use makes any sense?
Will my mp3 mplayer ever take off from ground? |
|
Back to top |
|
|
Ant
Joined: 06 Mar 2004 Posts: 306 Location: Canada
|
Posted: Wed Jun 15, 2005 7:00 am Post subject: Re: threads |
|
|
barrett9h wrote: | Code: |
int thread()
{
int i = 0;
while(!wants_to_quit) {
synchronized {
label.setLabel(std.string.toString(i));
}
writefln("i=?d", i);
++i;
std.c.time.sleep(1);
}
return 0;
}
|
This simple thread code makes the app window stop responding after some time. I can use it for a little while, while watching the label change, and soon it stops responding at all, it not even redraws on an expose. The thread continues to run, tough, as it continue to print on stdout. Then I have to ctrl-C on the console to stop it and close the stalled window.
Does (dyn)DUI plays nice with threads?
Am I doing something wrong?
Does the 'synchronized' use makes any sense?
Will my mp3 mplayer ever take off from ground? |
Threads are a known problem on DUI.
I'm not sure what's the problem.
Any help is welcome.
Antonio Monteiro |
|
Back to top |
|
|
barrett9h
Joined: 02 May 2005 Posts: 26 Location: Brazil
|
Posted: Sun Jun 19, 2005 7:26 am Post subject: workaround |
|
|
Ok, I found a way to workaround the problem:
Code: | int thread() {
int i = 0;
while(running) {
new_label = std.string.toString(i);
++i;
std.c.time.sleep(1);
}
return 0;
}
void go() { // this is called instead of DUI.dui.go()
while(running) {
DUI.dui().processPendingEvents();
std.c.time.usleep(10000);
if(new_label != label.getLabel())
label.setLabel(new_label);
}
}
|
|
|
Back to top |
|
|
|