FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

threads

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
barrett9h



Joined: 02 May 2005
Posts: 26
Location: Brazil

PostPosted: Wed Jun 15, 2005 5:14 am    Post subject: threads Reply with quote

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
View user's profile Send private message MSN Messenger
Ant



Joined: 06 Mar 2004
Posts: 306
Location: Canada

PostPosted: Wed Jun 15, 2005 7:00 am    Post subject: Re: threads Reply with quote

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
View user's profile Send private message
barrett9h



Joined: 02 May 2005
Posts: 26
Location: Brazil

PostPosted: Sun Jun 19, 2005 7:26 am    Post subject: workaround Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group