Optimus1
Optimus1

Reputation: 448

CEF Browser and multiple threads

Please explain me:

Suppose I created three browsers at the same time and started loading the URL in them CefBrowserHost::CreateBrowser(...).

Next, the loading goes to the example on void OnLoadEnd().

In OnLoadEnd() I will check the thread id:

void OnLoadEnd() override
{
    std::cout << "OnLoadEnd_this_thread_ID:" << std::this_thread::get_id() << std::endl;
}

All calls to OnLoadEnd() for all three browsers will have the same identifier thread.

It turns out that loading of browsers goes to one thread?

And if, for example, just for an example, I launch some kind of heavy calculation in OnLoadEnd(), then the loading of the rest of the URLs will stop.

Is it possible to somehow run browsers in different thread? Or all the same, all browsers can only work in one thread?

Upvotes: 0

Views: 1297

Answers (1)

Vladimir
Vladimir

Reputation: 2257

CEF inherits the Chromium Multi-Process architecture and threading model. I suppose the OnLoadEnd function is invoked on the UI thread. If you block it, you will block the main Chromium thread where UI is rendered and all user actions such as mouse and keyboard input are processed.

I don't think by blocking UI thread you block loading of the rest of the URLs, because Chromium loads resources in a separate Chromium process. All network activity is working there. By blocking OnLoadEnd, you block other notifications that are staying in a message queue and waiting until you release UI thread.

Anyway, if you need to launch some kind of heavy calculation, then do it in a separate thread and don't block Chromium UI thread.

Upvotes: 2

Related Questions