Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


FreeRTOS+TCP sockets in multiple threads.

Posted by captainjerk on July 14, 2016

Hello. What I want to achieve is to have multiple threads, each responsible for its own protocol. I am starting two threads and initialize two queues (Q1, Q2) (to pass the messages through them). Upon receiveing the message from queue, thread is supposed to open a socket, dump the message and eventually close the connection. What actually happens is, when I post messages like this: xQueueSend(Q1, msg1, 0) delay xQueueSend(Q2, msg2, 0) Everything works and both remote servers receive messages, but if no delay inserted, then one thread (I guess the one that calls FreeRTOSconnect later) fails to connect (connect() always returns ERRNOTIMEOUT). What could be wrong? Does not sockets supposed to work simultaneous?

FreeRTOS+TCP sockets in multiple threads.

Posted by rtel on July 14, 2016

I'm afraid there is not enough information in your post to fully understand your usage scenario, or how you are using the sockets, to be able to provide a full answer.

As far as using sockets from multiple threads go:

Any number of threads (tasks) can use FreeRTOS+TCP at any time, however there is a restriction on how tasks can share a single socket as follows: If you use the SAME socket from more than one thread then only one of the threads can write to the socket and only one of the threads can read from the socket - you can not have more than one thread both reading to and writing from the SAME socket.

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

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner