sys_thread_new vs. xTaskCreate

manug wrote on Wednesday, November 21, 2012:

Hello everybody,

I am new to FreeRtos and i have managed to create several tasks and do some task handling,. Then i started to get an lwIP example running with freertos. During my tentetive steps with freeRtos i created tasks wth xTaskCreate() and this worked well for me, also this is the way documented in the freeRTOSReferenceManual. But in the lwIP example, the tasks are created by using sys_thread_new.

Can somebody explain the differences between  the two functions? Are there advantages/disadvantages using the one or another?

manug wrote on Wednesday, November 21, 2012:

reading the documentation could help a lot…. :slight_smile:

If threads are supported by the underlying operating system and if
such functionality is needed in lwIP, the following function will have
to be implemented as well:

- sys_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)

  Starts a new thread named “name” with priority “prio” that will begin its
  execution in the function “thread()”. The “arg” argument will be passed as an
  argument to the thread() function. The stack size to used for this thread is
  the “stacksize” parameter. The id of the new thread is returned. Both the id
  and the priority are system dependent.

Just so there is an answer as opposed to someone say “Read the documentation”.
sys_thread_new calls xTaskCreate so they are almost the same. In the lwip (light weight Internet Protocol) examples, they use sys_thread_new and say all lwip calls should be from threads created with that call. If you look at the code, it doesn’t do much more than call xTaskCreate but it is a wrapper so that if you port your lwip code to other OS’s, you won’t have to change your code. Hope that helps for the next person who searches.

Thank you for taking time and posting the response.

1 Like