Threadsafe errno
Posted: Fri Sep 17, 2021 5:52 pm
Hello
I am using ESP-IDF 4.3 and need to evaluate the error reason for some library functions (such as for example "read()") by checking the value of "errno".
However, it seems that the errno variable is not thread safe and could report a wrong value set by another task.
I thought about putting the function call and evaluation of errno into a critical section (vTaskSuspendAll() / xTaskResumeAll()), but that did not work, as it is not allowed to use blocking functions inside a critical section.
Another idea would be to store the errno in each tasks local storage, but I have no idea, how to achieve this; especially because some libraries (for example newlib) directly write to the errno variable without using seterrno() routine.
There seems to be some preparation already done in the TCB in freertos/tasks.c
but that member is not referenced anywhere else.
Any idea how to make the errno threadsafe?
I am wondering if I am the only one facing this issue...
Thanks & best regards
Daniel
I am using ESP-IDF 4.3 and need to evaluate the error reason for some library functions (such as for example "read()") by checking the value of "errno".
However, it seems that the errno variable is not thread safe and could report a wrong value set by another task.
I thought about putting the function call and evaluation of errno into a critical section (vTaskSuspendAll() / xTaskResumeAll()), but that did not work, as it is not allowed to use blocking functions inside a critical section.
Another idea would be to store the errno in each tasks local storage, but I have no idea, how to achieve this; especially because some libraries (for example newlib) directly write to the errno variable without using seterrno() routine.
There seems to be some preparation already done in the TCB in freertos/tasks.c
Code: Select all
#if( configUSE_POSIX_ERRNO == 1 )
int iTaskErrno;
#endif
Any idea how to make the errno threadsafe?
I am wondering if I am the only one facing this issue...
Thanks & best regards
Daniel