cFS icon indicating copy to clipboard operation
cFS copied to clipboard

`CFE_SB_AllocateMessageBuffer()` fails in multi-threaded context

Open arya-pathak opened this issue 1 year ago • 3 comments

I am running cFS over Linux on an x86-64 machine. In the main function of my cFS app, I have created a thread through pthread_create(). Inside this thread, I read from a socket, and on receiving data I call another function that sends this data over the software bus. However, here the call to CFE_SB_AllocateMessageBuffer() always fails and returns NULL. On further inspection, the call to CFE_ES_GetAppID() is failing. This was never happening when the app was single-threaded. Any fixes for this?

CC: @rkshthrmsh

arya-pathak avatar Feb 23 '25 18:02 arya-pathak

Don't use pthread_create. Use CFE_ES_CreateChildTask to create child tasks in your app.

jphickey avatar Feb 24 '25 13:02 jphickey

This fixes the issue, thanks. Why does a newly created thread from native OS APIs lose context?

arya-pathak avatar Feb 24 '25 15:02 arya-pathak

Could you help me understand the consequences of using native OS APIs instead of cFE/OSAL-specific ones? For operations tarring or copying files, I'm using system("cp a b"); or system("tar -xvf cpu1.tar.xz"); and these are behaving unreliably. Is there any way to do this through OSAL/cFE APIs? If not, is it dangerous to use Linux' system() function?

arya-pathak avatar Feb 25 '25 17:02 arya-pathak