static WResource and haveMoreData() thread safety
Added by Emeric Poupon about 4 years ago
Hello,
I would like to do the following in a static WResource:
WResource::handleRequest()
{
...
Wt::Http::ResponseContinuation *continuation {response.createContinuation()};
continuation->setData(XXX);
continuation->waitForMoreData();
XXX->asyncWaitForData([&]()
{
// this could actually be called at any time, from a completely separate thread
continuation.haveMoreData();
});
}
Question: is it safe? What if haveMoreData() is called immediately during the request handling?
(In a non static resource, I could easily make the resource takes the Application lock, and post a callback in my asyncWaitForData lambda in order to make sure the continuation is not accessed in parallel.)
Replies (2)
RE: static WResource and haveMoreData() thread safety - Added by Roel Standaert about 4 years ago
That should normally be fine, except for the part where you capture the continuation pointer by reference. I think you mean to capture it by value.
RE: static WResource and haveMoreData() thread safety - Added by Emeric Poupon about 4 years ago
Ok thanks! (Indeed you are right about the capture by copy!)