what if i need to protect some_var from concurrent writers, but not protect from concurrent readers (avr port of nil)
void write_some_var(uint16_t v)
{
chSemWait(&s1); //concurrent writers must suffer
some_var = v;
chSemSignal(&s1);
}
uint16_t read_some_var(void)
{
chSemWait(&s1); //concurrent readers starvation?
auto r = some_var;
chSemSignal(&s1);
return r;
}
readers vs writers in nil
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: readers vs writers in nil
Hi,
You may try this: http://en.wikipedia.org/wiki/Readers%E2 ... rs_problem
In my opinion, if you just need to access a variable then it is advisable to use a critical zone, not semaphores: chSysLock() and chSysUnlock();
Giovanni
You may try this: http://en.wikipedia.org/wiki/Readers%E2 ... rs_problem
In my opinion, if you just need to access a variable then it is advisable to use a critical zone, not semaphores: chSysLock() and chSysUnlock();
Giovanni
Who is online
Users browsing this forum: No registered users and 17 guests