This now works for a single session but not for every session.
What I want is that all sessions will update their ExampleWidget when one of
them is updated.

Are you aware that you guys are using boost.signal and not boost.signal2
behind the hood?
Is it possible that it will also cause problems?
boost.signal isn't thread safe while boost.signal isn't.

2010/1/21 Koen Deforche <[email protected]>

> Hey Omer,
>
> 2010/1/20 omer katz <[email protected]>:
> > Here's my current test case code:
> >>
> >> #include <Wt/WApplication>
> >> #include <Wt/WPushButton>
> >> #include <Wt/WLineEdit>
> >>
> >> #include <iostream>
> >> #include <boost/thread.hpp>
> >>
> >> using namespace Wt;
> >> using namespace boost;
> >> using namespace std;
> >>
> >> class ExampleWidget;
> >> class CometTestApplication : public WApplication
> >> {
> >> public:
> >>   CometTestApplication(const WEnvironment& env);
> >>     ExampleWidget *t;
> >> };
> >>
> >> class ExampleWidget : public WLineEdit
> >> {
> >>     boost::thread updater;
> >>
> >> public:
> >>     void startBigWork()
> >>     {
> >>         updater = boost::thread(boost::bind(&ExampleWidget::doWork,
> this,
> >> WApplication::instance(), text()));
> >>
> >>        wApp->enableUpdates(true);
> >>     }
> >>
> >>     ExampleWidget()
> >>     {
> >>         keyWentUp().connect(SLOT(this, ExampleWidget::startBigWork));
> >>     }
> >>
> >>     void doWork(WApplication *app, const WString s)
> >>     {
> >>         CometTestApplication *myApp = static_cast<CometTestApplication
> >> *>(app);
> >>       myApp->attachThread();
> >>
> >>       // do work...
> >>
> >>       // if you want to update the GUI:
> >>       {
> >>
> >>         WApplication::UpdateLock uiLock = myApp->getUpdateLock(); //
> RAII
> >> lock
> >>         cout << endl << s << endl;
> >>
> >>         myApp->t->setText(s + s);
> >>
> >>         cout << endl << myApp->t->text() << endl;
> >>
> >>         // if using server push, push now the changes to the client
> >>         myApp->triggerUpdate();
> >>       }
> >>
> >>       // finally, when the work is done, we can disable updates again
> >>       myApp->enableUpdates(false);
> >>     }
> >>
> >> };
> >>
> >> CometTestApplication::CometTestApplication(const WEnvironment& env)
> >>   : WApplication(env)
> >> {
> >>     t = new ExampleWidget();
> >>
> >>     root()->addWidget(t);
> >> }
> >>
> >> WApplication *createApplication(const WEnvironment& env)
> >> {
> >>   return new CometTestApplication(env);
> >> }
> >>
> >> int main(int argc, char **argv)
> >> {
> >>   return WRun(argc, argv, &createApplication);
> >> }
> >
> > It occasionally runs on my session but most of the time it doesn't. When
> it
> > does it just sets it a lot of times.
> > It doesn't update any sessions.
> > It looks like the thread is taking forever to run comparing to normal
> code.
> > Any idea why?
>
> Thanks for the test code !
>
> I found two problems:
>  - There is no need to use attachThread() if you are going to grab the
> update lock when needed: you can only touch the application safely
> while holding the lock, and this code will also attach the thread for
> you while you have the lock. Unfortunately, doing attachThread()
> before grabbing the update lock resulted in not effectively taking the
> lock. This is silly and has been fixed.
>  - With that change, it works, but you can still get into trouble
> because you have a race condition in enabling and disabling server
> push. I have fixed this too by making server-push counter based so
> that you will only disable server push if you have a matching amount
> of setUpdatesEnabled(true) and setUpdatesEnabled(false).
>
> With these two fixes (in git), the modified test case below (which is
> only a simplification) works for me !
>
> Regards,
> koen
>
> #include <Wt/WApplication>
> #include <Wt/WContainerWidget>
> #include <Wt/WPushButton>
> #include <Wt/WLineEdit>
>
> #include <iostream>
> #include <boost/thread.hpp>
>
> using namespace Wt;
> using namespace boost;
> using namespace std;
>
> class ExampleWidget;
> class CometTestApplication : public WApplication
> {
> public:
>  CometTestApplication(const WEnvironment& env);
>    ExampleWidget *t;
> };
>
> class ExampleWidget : public WLineEdit
> {
>    boost::thread updater;
>
> public:
>    void startBigWork()
>    {
>        wApp->enableUpdates(true);
>        updater = boost::thread(boost::bind(&ExampleWidget::doWork,
> this, WApplication::instance(), text()));
>    }
>
>     ExampleWidget()
>    {
>       keyWentUp().connect(SLOT(this, ExampleWidget::startBigWork));
>    }
>
>    void doWork(WApplication *app, const WString s)
>    {
>       // app->attachThread(); not needed and did not work; does now
>       // do work...
>
>      // if you want to update the GUI:
>      {
>
>         WApplication::UpdateLock uiLock = app->getUpdateLock(); // RAII
> lock
>        cout << endl << s << endl;
>
>        setText(s + " " + s);
>
>        cout << endl << text() << endl;
>
>        // if using server push, push now the changes to the client
>         app->triggerUpdate();
>
>        app->enableUpdates(false);
>      }
>    }
> };
>
> CometTestApplication::CometTestApplication(const WEnvironment& env)
>  : WApplication(env)
> {
>    t = new ExampleWidget();
>
>    root()->addWidget(t);
> }
>
> WApplication *createApplication(const WEnvironment& env)
> {
>  return new CometTestApplication(env);
> }
>
> int main(int argc, char **argv)
> {
>  return WRun(argc, argv, &createApplication);
> }
>
>
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for
> Conference
> attendees to learn about information security's most important issues
> through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to