After r1716 I started observing SEGFAULTs in the application I am developing.
A careful code inspection pointed out an issue in the POSIX implementation of vos_thread.c (I don't know about the other platforms): the returned VOS_THREAD_T handle (the first argument of vos_threadCreate()) is a ponter to a struct that is local to the vos_threadCreate() function and that does not exist anymore once the function call returns. So the returned value is a "potentially valid" pointer to "invalid data" (expecially if more than one thread is managed).
I used this pointer with vos_threadIsActive() and the inner call to pthread_kill() caused the SEGFAULT.
One solution could be add the static qualifier to the local structure; but I do not think it is a reasonable solution since the content of the handle would be overwritten each time a new thread is started besides the first one.
To be more precise, what I called "a struct that is local to the
vos_threadCreate()" is thepthread_t hThreadvariable.Since it is an opaque object I supposed it to be a struct.
But whether or not it is assignable, at present time it is not returned in the right way.
Hi Lorenzo,
the pointer supplied to vos_threadCreate() as pThread must point to a memory area with sizeof(VOS_THREAD_T) – this is not really mentioned in the user manual, sorry!
And vos_threadCreate() should check for NULL-pointer args, as well.
Regarding the vos_threadIsActive() function: The change made in r1716 does not do any good. pthread_kill returns the same error as pthread_getscheduleparam on a false or inactive thread.
It will be reverted.
Threads are currently only used by the local test applications. See test/localtest/api_test.c as example. The threadId (type VOS_THREAD_T) is statically allocated in a session structure, and vos_threadCreate gets a pointer to that space...
@Armin: Can you please add a comment in the User Manual about allocation of VOS_THREAD_T before providing a pointer to vos_threadCreate()?
-> Rev 1724