CefPostTask - TID for REQUIRE_MAIN_THREAD(); is not TID_UI?

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefPostTask - TID for REQUIRE_MAIN_THREAD(); is not TID_UI?

Postby HarmlessDave » Mon Feb 12, 2018 6:49 pm

CEF 3.3239.1723.g071d1c1 Windows, 32-bit,

I tried to call RootWindowManager::GetWindowForBrowser from a function called using CefPostTask(TID_UI, base::Bind( myfunction, ... )) with this code:

Code: Select all
scoped_refptr<client::RootWindow> rootwin = client::MainContext::Get()->GetRootWindowManager()->GetWindowForBrowser(browser_id);


It tripped the check for REQUIRE_MAIN_THREAD(); == DCHECK(CURRENTLY_ON_MAIN_THREAD()) == client::MainMessageLoop::Get()->RunsTasksOnCurrentThread() == return (thread_id_ == base::PlatformThread::CurrentId());

So apparently TID_UI is not the thread for the main message loop when settings.multi_threaded_message_loop = true;

Is this correct? I can hack around it by using a Windows PostMessage with a control ID, then have the message event call myfunction, but it would be cleaner to be able to do CefPostTask(TID_MAIN, ... if there was such a thing as TID_MAIN. Or if TID_UI really was the UI thread when multi_threaded_message_loop = true which it apparently is not?

If needed I can put together a version of this using CefClient.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: CefPostTask - TID for REQUIRE_MAIN_THREAD(); is not TID_

Postby magreenblatt » Mon Feb 12, 2018 7:16 pm

So apparently TID_UI is not the thread for the main message loop when settings.multi_threaded_message_loop = true;

Correct.

I can hack around it by using a Windows PostMessage with a control ID, then have the message event call myfunction

This is the correct approach. See MainMessageLoopMultithreadedWin in cefclient for an example.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CefPostTask - TID for REQUIRE_MAIN_THREAD(); is not TID_

Postby HarmlessDave » Mon Feb 12, 2018 7:33 pm

Thanks. Most of our code is already like that, I just was expecting the _UI thread to be the message loop thread and wanted to make sure I wasn't missing something.
HarmlessDave
Expert
 
Posts: 370
Joined: Fri Jul 11, 2014 2:02 pm

Re: CefPostTask - TID for REQUIRE_MAIN_THREAD(); is not TID_

Postby magreenblatt » Mon Feb 12, 2018 7:46 pm

Don't use multi_threaded_message_loop = true if you want the main thead to be the UI thread :)
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: ElAndLivia and 96 guests