How to create client in child thread

袁嘉伟 yuanjw1025 at 163.com
Fri Jun 24 03:15:32 UTC 2016


在 2016-06-23 21:13:28,"Pekka Paalanen" <ppaalanen at gmail.com> 写道:
>On Thu, 23 Jun 2016 14:52:23 +0800 (CST)
>袁嘉伟 <yuanjw1025 at 163.com> wrote:
>
>> Hi Pekka:
>> 
>> Sorry to take you some time. It's still this issue.
>> I made a test that using 'pthread' to created another thread, and then created the display in the child thread.
>> But program was blocked when connecting to a server(wl_display_connect). It should be pending according to log.
>> However, I called the renderFrames() in main thread, it ran correctly and displayed the triangle.
>> Could you tell me what causes the issue happend. 
>> 
>> 
>> 
>> 
>> voidSurfaceManagerClient::initializeThread()
>> {
>>     pthread_t lifeThread;
>> pthread_create(&lifeThread, NULL, &SurfaceManagerClient::renderFrames, NULL);    
>> }
>> 
>> 
>> void SurfaceManagerClient::renderFrames()
>> {
>> struct sigaction sigint;
>> struct display display = { 0 };
>> struct window  window  = { 0 };
>> int i, ret = 0;
>> window.display = &display;
>> display.window = &window;
>> window.window_size.width  = 250;
>> window.window_size.height = 250;
>> window.buffer_size = 32;
>> window.frame_sync = 1;
>> for (i = 1; i < m_argc; i++) {
>> if (strcmp("-f", m_argv[i]) == 0)
>> window.fullscreen = 1;
>> else if (strcmp("-o", m_argv[i]) == 0)
>> window.opaque = 1;
>> else if (strcmp("-s", m_argv[i]) == 0)
>> window.buffer_size = 16;
>> else if (strcmp("-b", m_argv[i]) == 0)
>> window.frame_sync = 0;
>> else if (strcmp("-h", m_argv[i]) == 0)
>> usage(EXIT_SUCCESS);
>> else
>> usage(EXIT_FAILURE);
>> }
>> display.display = wl_display_connect(NULL);
>> assert(display.display);
>> display.registry = wl_display_get_registry(display.display);
>> wl_registry_add_listener(display.registry, &registry_listener, &display);
>> 
>> 
>> int a = wl_display_dispatch(display.display);
>> init_egl(&display, &window);
>> create_surface(&window);
>> init_gl(&window);
>> display.cursor_surface = wl_compositor_create_surface(display.compositor);
>> 
>> 
>> sigint.sa_handler = signal_int;
>> sigemptyset(&sigint.sa_mask);
>> sigint.sa_flags = SA_RESETHAND;
>> sigaction(SIGINT, &sigint, NULL);
>> 
>> 
>> while (running && ret != -1) {
>> wl_display_dispatch_pending(display.display);
>> redraw(&window, NULL, 0);
>> }
>>     fprintf(stderr, "simple-egl exiting\n");
>>     destroy_surface(&window);
>> 
>>     fini_egl(&display);
>> 	wl_surface_destroy(display.cursor_surface);
>> 	if (display.cursor_theme)
>> 		wl_cursor_theme_destroy(display.cursor_theme);
>> 
>> 	if (display.shell)
>> 		xdg_shell_destroy(display.shell);
>> 
>> 	if (display.ivi_application)
>> 		ivi_application_destroy(display.ivi_application);
>> 
>> 	if (display.compositor)
>> 		wl_compositor_destroy(display.compositor);
>> 
>> 	wl_registry_destroy(display.registry);
>> 	wl_display_flush(display.display);
>> 	wl_display_disconnect(display.display);
>> 
>> 	return 0;
>> }
>> Best regards,
>> Anthenony
>> 
>
>Hi,
>
>sorry, but I can't make sense from the spaghetti above, nor do I have
>time to debug your application for you, especially when it has huge
>parts outside of my expertise (everything about SurfaceManager). If you
>can create a stand-alone C program that shows the problem, then it
>might be possible to take a look, but no promises.
>
>Also signals will be delivered to random threads unless you
>specifically block them.
>
>I have no idea why wl_display_connect() from a secondary thread would
>block.
>
>
>Thanks,
>pq

Hi:
I have created a stand-alone C program, which could show the problem.
It was blocked in wl_display_dispatch this time.I was very helpless.
I hope you might take a look if you have time. 
Thanks.


    









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160624/8b7e38f0/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: main.c
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20160624/8b7e38f0/attachment-0001.c>


More information about the wayland-devel mailing list