lc-soft / LCUI

C library for building user interfaces
https://lcui-dev.github.io
MIT License
4.13k stars 356 forks source link

[WebAssembly] the test program will block on the main thread #207

Closed lc-soft closed 1 year ago

lc-soft commented 4 years ago

Describe the bug I tried to compile the source code of LCUI into WebAssembly, but when running the test program, I found that it would block on the main thread

To Reproduce Steps to reproduce the behavior:

emconfigure ./configure --enable-video-output=no --with-openmp=no --disable-shared
make
cd test
emcc -s WASM=1 -s USE_PTHREADS=1 -I../include -Wall -D _GNU_SOURCE -pthread -O2 -o test.html test.o libtest.o test_mainloop.o test_charset.o test_string.o test_strpool.o test_linkedlist.o test_object.o test_thread.o test_font_load.o test_css_parser.o test_xml_parser.o test_image_reader.o test_block_layout.o test_flex_layout.o test_widget_rect.o test_widget_opacity.o test_widget_event.o test_textview_resize.o test_textedit.o  ../src/.libs/libLCUI.a -lm -pthread

Expected behavior Not blocking.

Screenshots If applicable, add screenshots to help explain your problem. QQ截图20200404213424

Environment (please complete the following information):

Additional context

lc-soft commented 4 years ago

After commenting out the function that uses the thread, the test program can exit correctly.

#include <stdio.h>
#include <wchar.h>
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include "test.h"
#include "libtest.h"

int tests_count = 0;

int main(void)
{
    int ret = 0;
    Logger_SetLevel(LOGGER_LEVEL_OFF);
    ret += test_charset();
    ret += test_linkedlist();
    ret += test_string();
    ret += test_strpool();
    ret += test_object();
    //ret += test_thread();
    ret += test_font_load();
    ret += test_image_reader();
    //ret += test_xml_parser();
    //ret += test_widget_event();
    //ret += test_widget_opacity();
    //ret += test_textview_resize();
    //ret += test_textedit();
    //describe("test mainloop", test_mainloop);
    //describe("test css parser", test_css_parser);
    //describe("test block layout", test_block_layout);
    //describe("test flex layout", test_flex_layout);
    //describe("test widget rect", test_widget_rect);
    //PRINT_TEST_RESULT(ret);
    return ret - print_test_result();
}

20200404220025

lc-soft commented 4 years ago

Run test.js on node:

node --experimental-wasm-threads --experimental-wasm-bulk-memory test.js

image