I should make people aware of another problem: sharing variables between threads.
Code: Select all
double d;
void thread_1(void)
{
...
d+=10;
}
void thread_2(void)
{
double my_d = d;
...
}
What now might happen if both threads are running is the following:
Code: Select all
thread_1 thread_2
---------------------------------------------
writes lower part of d -
- reads lower part of d
- reads upper part of d
writes upper part of d -
And as a warning: the C standard doesn't guarantee that even operations on native types (like integers) are done as an atomic operation (in one part). You might have luck with such (it depends on the compiler-(version) and some other things), but to be sure you have to use either atomic operations or you need to use mutexes, semaphores or similiar to protect reads and writes on shared variables from simultaneous access. (And don't use plain integers as replacement for a real mutexes.)
Don't forget, the EV3 uses a real operating system and real threads are a lot different than e.g. threads in python, nbc or nxc.
Alexander Holler