Preventing concurrent processing?

View: New views
2 Messages — Rating Filter:   Alert me  

Preventing concurrent processing?

by Benjamin Smith :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having a problem with concurrent callbacks being generated.

Say that there are two buttons on the screen, each of which take a few moments
to process. If the user presses button A, and starts the process, and then
presses button B before A's callback is done, then both callbacks
are "running at the same time".

This has resulted in some inconsistent states and program crashes. (EG: the
callback for button A assumes that a certain object is defined, but since
button B was pressed before A was done, that object is no longer there)

Is this making sense? What's the best way to structure things to deal with
this issue?

As a side note, I have a function called "UpdateScreen()" that I use within
these intensive-processing functions as follows, so that the program "appears
responsive"... is this the problem?

Function UpdateScreen()
  {
  while (gtk::events_pending())
        gtk::main_iteration();
  }

-Ben

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
PHP-GTK General Mailing List (http://gtk.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: Preventing concurrent processing?

by kksou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Benjamin Smith wrote:
Say that there are two buttons on the screen, each of which take a few moments
to process. If the user presses button A, and starts the process, and then
presses button B before A's callback is done, then both callbacks
are "running at the same time".

This has resulted in some inconsistent states and program crashes. (EG: the
callback for button A assumes that a certain object is defined, but since
button B was pressed before A was done, that object is no longer there)

Is this making sense? What's the best way to structure things to deal with
this issue?
Hi Benjamin,

There are many ways to handle "concurrent" button clicks in PHP-GTK2. Below are three of the methods:
Method 1: using GObject::block()
Method 2: using GtkWidget::set_sensitive()
Method 3: GObject::emit_stop_by_name()

Sample codes as follows:
http://www.kksou.com/php-gtk2/articles/prevent-concurrent-button-clicks---Part-1---using-block.php
http://www.kksou.com/php-gtk2/articles/prevent-concurrent-button-clicks---Part-2---using-set-sensitive.php
http://www.kksou.com/php-gtk2/articles/prevent-concurrent-button-clicks---Part-3---using-emit-stop-by-name.php

Regards,
/kksou