2 years, 1 month ago.

How to pass a char array to a thread?

I have a char array of 32 characters. I'd like to pass this into a thread which starts executing once it gets all the 32 bits passed to it through some thread exchange means - and it cannot take any more than that even if there is more waiting in the queue. I am new to RTOS, to threads, and to transferring information between threads. Firstly, would I use a Queue or Mail? Secondly, what is a good way of learning how to setup and use this queue? There is so few examples on the mbed and not many tutorials, but maybe there is a similar hardware platform which is beginner-friendly to learn threading and messaging queues?

I'm sorry if this is a lot; I don't know where to start.

2 Answers

2 years, 1 month ago.

Hi, so try to write a simple code for test and when you can not push the code forward, place the code here and explain where is the problem. Maybe someone help.

I think maybe when you use a little bit imagination on these examples of RTOS APIs, you can achieve what do you want. https://os.mbed.com/docs/mbed-os/v5.11/apis/rtos.html

GL

2 years, 1 month ago.

I usually like to use mail if possible. This way you are sending a copy of the data and the receiving thread doesn't have to worry about sharing. The example here works fine for me. Just replace the data in the mail_t struct with the buffer you need.

https://os.mbed.com/docs/mbed-os/v5.11/apis/mail.html

And be sure you really need to add a thread before introducing the extra complexity.