Re: Race Conditions
Ala Qumsieh <[email protected]>
| Newsgroups | gmane.comp.lang.perl.tk |
|---|---|
| Message-ID | <[email protected]> |
--- edward barlow <[email protected]> wrote: > I appear to be getting a race condition in Perl/Tk. > I click on a user > interface element (a button) which redraws a > Tk::Tree and then click on > another button quickly (before the first element > finishes the tree redraw) > that also will cause a tree redraw. From what i can > tell, I end up > redrawing the tree twice simultaneously... I end up > with duplicate elements > and getting an error. Clicking slowly produces no > errors.. Is this normal > under a multi threaded version perl and is there a > way to force Tk events to > be single threaded... Tk is not thread safe. Your description is a bit vague, but I'm assuming that the Tk stuff all happens in the same thread. If that is the case, then you can do two options (assuming I understand your query): 1) Have a global variable, something like $treeRedraw, being set to 1 at the beginning of each function that repopulates your Tree, and reset to 0 at the end. Then your functions will only execute if $treeRedraw is set to 0. or 2) When the first button is clicked, the first thing it does is disable the second button, and only enable it at the end of the function. And vice versa. Theoretically, you can still get a race condition, but you'll need to drink a loooot of coffee to be able to press the two buttons simultaneously with a single mouse! --Ala __________________________________ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com -++**==--++**==--++**==--++**==--++**==--++**==--++**== This message was posted through the Stanford campus mailing list server. If you wish to unsubscribe from this mailing list, send the message body of "unsubscribe ptk" to [email protected]