Proper Way to Use TLS in Multithreaded Application


I am having trouble getting multiple TLS connections to run when using multiple threads. Right now I am having to force all my communication into a single thread as the following happens if I do not:

  • When two threads attempt to send or receive data at the same time, the device will hang waiting for a register SCE->REG_04H_b.B30.

Is there some sort of protection I can do to prevent this. What is best practice?

All the best

Which device is this? What TLS and TCP stack are you using?

I am using MbedTLS on a Renesas RA6 Chip. I’ve tried to solve the issue with mutexes, but I am wondering if the library itself needs adjustments or configs.

Have you read this - Thread safety and multithreading: concurrency issues — Mbed TLS documentation?