Question about thread generation in Xilinx SDK FreeRTOS + LWIP example source code

Dear FreeRTOS experts.

I have a question about SDK FreeRTOS + LWIP example source code.

In the following source code example (echo.c), the process_echo_request thread seems to be generated multiple (a lot of) times in infinite while loop.

sys_thread_new() is xTaskCreate() function.

void echo_application_thread()
{
  ...
  ...
	while (1) {
		if ((new_sd = lwip_accept(sock, (struct sockaddr *)&remote, (socklen_t *)&size)) > 0) {
			sys_thread_new("echos", process_echo_request,
				(void*)new_sd,
				THREAD_STACKSIZE,
				DEFAULT_THREAD_PRIO);
		}
	}
}

Is only one lwip_accept() thread generated?

Thank you very much.

Ick-Sung Choi.

The short answer is I don’t know, but the code looks like it is creating a thread for each accepted connection. You can find out by looking at how sys_thread_new() is implemented, or even placing a break point on that line and stepping into the function.

The sys_thread_new() is implemented as follows (Xilinx SDK FreeRTOS _ LWIP example code (echo.c)).

sys_thread_t sys_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority )
{
xTaskHandle xCreatedTask;
portBASE_TYPE xResult;
sys_thread_t xReturn;

xResult = xTaskCreate( pxThread, ( signed char * ) pcName, iStackSize, pvArg, iPriority, &xCreatedTask );

if( xResult == pdPASS )
{
	xReturn = xCreatedTask;
}
else
{
	xReturn = NULL;
}

return xReturn;

}

Reference :

https://www.ibm.com/support/knowledgecenter/SSLTBW_2.2.0/com.ibm.zos.v2r2.bpxbd00/accept.htm

The accept() call is used by a server to accept a connection request from a client. When a connection is available, the socket created is ready for use to read data from the process that requested the connection. The call accepts the first connection on its queue of pending connections for the given socket socket. The accept() call creates a new socket descriptor with the same properties as socket and returns it to the caller. If the queue has no pending connection requests, accept() blocks the caller unless socket is in nonblocking mode. If no connection requests are queued and socket is in nonblocking mode, accept() returns -1 and sets the error code to EWOULDBLOCK. The new socket descriptor cannot be used to accept new connections. The original socket, socket, remains available to accept more connection requests.

The code you posted shows a task being created, which was your original question, so I’m not sure if you still have a question. I’m not sure if you still have a question.