Page 1 of 1

General understanding of messages, semaphores etc

PostPosted: Mon May 21, 2018 9:28 am
by MD5003
Being a mechanical engineer I have some trouble understanding some of the principles in this whole message and semaphore system.
I am currently working on a robotics project using a teensy 3.6 and plan to use cocoOS for programming.

I have read some articles (mainly wikipedia) about multi tasking and what messages and semaphores are, but yet the whole principle is probably too abstract for me, not having the background of an actual programmer (especially in ┬Ác programming).

Could it cause problems to use global variables to communicate between different tasks instead of messages? How are semaphores used in general?

Are there any good ressources, preferably cocoOS samples, for seeing messages and semaphores "in action"?

Re: General understanding of messages, semaphores etc

PostPosted: Mon May 21, 2018 9:57 am
by peter
Hi,
thanks for planning to use cocoOS!

Semaphores are used to protect shared resources.
A global variable is a shared resource. If one task are updating it, it could potentially be interrupted, before the update operation is complete, by another task that tries to read the shared variable.
So it will read corrupted data.
In this case you should protect the variable by a semaphore.

By using messages in cocoOS instead, the OS takes care of protecting data and delivers it to the recipient.

If you mail me at info@cocoos.net and give me some hints about what you want to accomplish, I could help you get started.

Regards
Peter