Fish
September 17, 2025, 3:34pm
1
What do you want to achieve?
Call a function from a thread other than the LVGL thread
What have you tried so far?
Using lv_async_call() with a lv_lock()/lv_unlock to call a function on the next lvgl tick.
Code runs for a few seconds before segfaulting.
Code to reproduce
#include “lvgl/lvgl.h”
#include “lvgl/demos/widgets/lv_demo_widgets.h”
#include <pthread.h>
static void do_nothing(void * ptr){}
static void * nothing_thread(void *){
while(true){
lv_lock();
lv_async_call(do_nothing, NULL);
lv_unlock();
usleep(1000);
}
}
int main(){
lv_init();
lv_display_t * display = lv_sdl_window_create(1920,1080);
lv_indev_t * mouse = lv_sdl_mouse_create();
lv_demo_widgets();
pthread noThread;
pthread_create(&noThread, NULL, nothing_thread, NULL);
while(true){
lv_timer_handler_run_in_period(5);
}
}
Screenshot and/or video
Environment
SDL simulator (Desktop)
LVGL version: 9.3
When you call an execution of a piece of code (function) via lv_async_call(), you don’t need to call lv_lock() and lv_unlock() before and after.
Fish
September 22, 2025, 1:41pm
3
I tried removing lv_lock() and lv_unlock(). The code still compile and runs but still segfaults shortly after
It seems to crash with the error:
Asserted at expression: block_is_free(block) && “block must be free” lv_tlsf.c:716
OR
block_locate_free: Asserted at expression: block_size(block) >= size lv_tlsf.c:774
Hi
Do you have #define LV_USE_OS LV_OS_PTHREAD set?
Tried your code, and with that property set, and with the lv_lock() / lv_unlock() don’t have that issue, but if either LV_USE_OS is not set or not using lv_lock() / lv_unlock() will generate the seg fault.
Fish
September 23, 2025, 2:59pm
5
I had #define LV_USE_OS LV_OS_NONE set. After changing to LV_OS_PTHREAD it appears to have fixed the segfaulting issue. Thanks!