hi all,
is it possible to create array so that it can be change from one thread and can be read from other threads?
I need to instantly fill array with data in one thread and use data in several other threads. other threads does not modifying array content- only reading it.
reading and writing processes are not synchronized -so use of channels does not seems to be a good idea...
I understand that care should be taken by programmer to avoid simultaneous access to array from threads, that I can take care of by creating two arrays and switch between then - one is in filling and one is in reading mode so the will be no crossing of access.
thanks
XC-1A array used by mutiple threads.
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
-
- Member++
- Posts: 22
- Joined: Mon Jun 07, 2010 12:50 pm
Hi Cicga,
To prevent users having problems with sharing variables, XC doesnt allow variables to be shared between threads. There are certain circumstances where sharing a variable between threads is useful, and the one you describe is one of them.
If you want to share a variable, you can do this using C. You can write functions in C to read and write to the shared variable (array in your case).
The double buffering mechanism is a common approach, although isnt always necessary. If one thread is always reading and the other thread is always writing, the array access is safe.
Hope this helps.
Ali
To prevent users having problems with sharing variables, XC doesnt allow variables to be shared between threads. There are certain circumstances where sharing a variable between threads is useful, and the one you describe is one of them.
If you want to share a variable, you can do this using C. You can write functions in C to read and write to the shared variable (array in your case).
The double buffering mechanism is a common approach, although isnt always necessary. If one thread is always reading and the other thread is always writing, the array access is safe.
Hope this helps.
Ali
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
hi Ali,
thanks a lot, I will try to do it through C...
cicga
thanks a lot, I will try to do it through C...
cicga
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
Ali,
its work but as long as both threads running on the same core.
Is it possible to make threads running on different cores use the same array?
my problem is that I am sending data from:
1. uart running on sdtcore[0]
2. control thread, that can be placed on any core - in my case I put it on core1:
and executive threads that are reading data can run on any core 1,2 or 3.
thanks
its work but as long as both threads running on the same core.
Is it possible to make threads running on different cores use the same array?
my problem is that I am sending data from:
1. uart running on sdtcore[0]
2. control thread, that can be placed on any core - in my case I put it on core1:
and executive threads that are reading data can run on any core 1,2 or 3.
thanks
-
- Member++
- Posts: 22
- Joined: Mon Jun 07, 2010 12:50 pm
Hi Cicga,
Each XCore has its own local memory (64KB) which can only be accessed by the threads running on that core. For example in a 2 core device, the threads on core0 can access core0 memory, but the threads on core1 cannot access core0 memory.
Channels are the way to share data between threads, and allow all threads in the system to communicate independent of which core the thread is on.
Ali
Each XCore has its own local memory (64KB) which can only be accessed by the threads running on that core. For example in a 2 core device, the threads on core0 can access core0 memory, but the threads on core1 cannot access core0 memory.
Channels are the way to share data between threads, and allow all threads in the system to communicate independent of which core the thread is on.
Ali
-
- Active Member
- Posts: 51
- Joined: Tue Oct 11, 2011 4:48 pm
thanks Ali