WResource updating UI crashes with attachThread and getUpdateLock
Added by Neel Basu over 8 years ago
I have multiple WResources attached to the same WServer. Both updating the UI.
The first one is updating the UI with no problem by emitting signals on Wt::WApplication
derived application.
The second one is emitting boost::signals2
which in turn is being slotted to a WContainer
based widget.
The second one crashes whenever it tries to create a new widget.
I can see both of these threads are different thread that is executing Wt::WServer::waitForShutdown (I thought that is the main/UI thread, I don't know for sure, However it looks like it waits for all other threads). I can see WIOService::run at the bottom of all these threads.
If I try to call any of these inside the slot that digests the boost signals2
Wt::WApplication::instance()->attachThread(true);
Wt::WApplication::UpdateLock lck = Wt::WApplication::instance()->getUpdateLock();
Wt::WApplication::instance()->attachThread(false);
It crashes too
Replies (1)
RE: WResource updating UI crashes with attachThread and getUpdateLock - Added by Koen Deforche over 8 years ago
It's not clear if you're using a 'static' resourc or a 'dynamic resource. Therefore I'll explain both cases:
Dynamic resource¶
A dynamic WResource is associated with a single application, but is (for performance reasons) allowed to handle requests concurrently with the event loop. Therefore, if you want to manipulate the UI, you need to take the UpdateLock:
Wt::WApplication::UpdateLock lock(Wt::WApplication::instance());
if (lock) {
// manipulate UI, or emit a signal to manipulate the UI, etc...
}
As long as you do that, it should be fine.
Static resource¶
A static WResource has no relation to any of the UI threads, and thus you also need to take the lock of the correct UI. Wt::WApplication::instance() will however return 0 as the current thread (handling the resource request) has no relation to an application instance. You need thus somehow communicate from the application to the resource to give it the correct application it can take its lock.