Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


How to make a Web Server Demo application multithreaded?

Posted by joe0x7f on January 13, 2016

Hello Everyone,

I would like to know what your recommended options are for making the FreeRTOS ARM Cortex-M3 Web Server Demo application multithreaded, please?

I assume there is some way to accept() a TCP/IP cnnection on port 80 within a FreeRTOS Task and then hand the TCP/IP read/write work off to a worker thread?

Are the threads created before or after the accept()?

Does this require one FreeRTOS Task for each thread?

Is there a TCP/IP stack recommended that I use?

Switching gears, any suggestions on fork()ing versus spinning up a worker thread? I'm not sure fork()ing is available in FreeRTOS either? Perhaps a fork() is really creating another FreeRTOS Task on the fly?

As I remember from the FreeRTOS class, it seemed that making a FreeRTOS Task on the fly was frowned upon?

Basically, I'm not sure what options I have in FreeRTOS to make respectable, stable multithreaded or forked TCP/IP applications?



How to make a Web Server Demo application multithreaded?

Posted by rtel on January 13, 2016

Are you talking about the FreeRTOS+TCP web server example here? http://www.freertos.org/FreeRTOS-Plus/FreeRTOSPlusTCP/HTTPwebServer.html . That (which at the moment is quite basic) and the FTP server (which is more sophisticated) http://www.freertos.org/FreeRTOS-Plus/FreeRTOSPlusTCP/FTPServer.html currently run in the same RTOS task. So one 'server task' is handling all HTTP and FTP connections, which is very efficient from a RAM point of view, and not too inefficient from a run time and throughput point of view as the file system is a bottleneck anyway as all the threads want to access the same file system. You can see a little video demonstration of both running at once, along with three or four other TCP/IP and UPD/IP examples, all running simultaneously in less than 190K RAM. In fact, it would work in less RAM too. http://www.freertos.org/FreeRTOS-Plus/FreeRTOSPlusTCP/TCP-IPIn190KRAM_Video.html

How to make a Web Server Demo application multithreaded?

Posted by rtel on January 13, 2016

Should have said the server task uses FreeRTOS_select() to manage multiple connections.

How to make a Web Server Demo application multithreaded?

Posted by joe0x7f on January 13, 2016

Great! Thank you for the pointers! I will take a look.

How to make a Web Server Demo application multithreaded?

Posted by heinbali01 on January 14, 2016

Hi Joe,

Some more background information in addition to what Richard wrote:

It is a classical approach to have a TCP server that calls accept() and forks for every new connection (so fork() comes after a successful accept()) A child process or thread will exist as long as the TCP connection is alive.

That approach works OK in an environment with plenty of resources (lots of RAM).

In an embedded environment, we must be careful with resources. When a browser opens an interactive page, with some Java Script and asynchronous requests, it will open 6 connections to port 80.

A HTML or FTP server uses:

1) A disk 2) A network interface 3) CPU time

In most cases, there is only one of each: a single disk, which is often a memory card or flash. A single network adapter (peripheral). And finally, most smaller CPU's have a single core. So you can ask your self: what's the use of creating extra tasks, if all those tasks are competing to use shared resources?

The FreeRTOS_select() library function is essential: it lets the server wait for specific events on any of the sockets in a socket-set. The server sockets (for which bind(), listen(), and accept() is called) are included in this socket-set, they wait for a READ event. Another socket has it's transmission buffer full of data, and it will wait for a WRITE event. Yet a third socket has sent a file and it waits for a READ event.

FreeRTOS_listen() has a parameter called "backlog". That protects the application against getting too many concurrent connections.


How to make a Web Server Demo application multithreaded?

Posted by joe0x7f on January 14, 2016

Thanks, Hein! This is very helpful additional information.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists