Hi,
Could I have an example of using pthread,h with thread_create to run a thread with other functions?
Ken
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
Could I have an example of using pthread,h with thread_create to run a thread with other functions?
Ken
Hi Ken,
pthread for SYS/BIOS is documented here: http://processors.wiki.ti.com/index.php/SYS/BIOS_POSIX_Thread_%28pthread%29_Support
You need to add this to your .cfg file:
var Settings = xdc.useModule(‘ti.sysbios.posix.Settings’);
In the .c file, #include <ti/sysbios/posix/pthread.h>
To create a thread:
typedef void *(*ThreadFxn)(void *arg);
pthread_t thread;
pthread_attr_t pattrs;
int threadArg = 1;
pthread_attr_init(&pattrs);
retc = pthread_create(&thread, &pattrs, (ThreadFxn)threadFxn,
(void *)threadArg);
static void *threadFxn(void *arg)
{
int n = (int)arg;
...
}
You can also look at posix examples on the web for pthread_create() examples.
Best regards,
Janet
Hi Janet,
Thanks for the info.
I have read some of the online training material. I will read more.
For the pthread.h appoach, please verifiy the following
1. no while loop on top level
2. every function has to be run inside a thread
3. use thread_create for each thread open and execute.
4. add bios_start at the end
Ken
2.
Hi Ken,
The steps you describe above are correct for the main() function in BIOS, except I'm not sure exactly what you mean be "2. every function has to be run inside a thread". There are some pthread functions that can only be run from threads, such as pthread_join(). The 'create' functions (e.g., pthread_create) can be called from main(). BIOS pthreads are built on top of BIOS Tasks, so the rules that apply to BIOS Tasks also apply to pthreads. The link that I referred to in an earlier post, contains a table at the end of the page, listing the BIOS pthread APs and whether they can be called from main() or a BIOS task.
Best regards,
Janet