readers vs writers in nil

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
acr
Posts: 14
Joined: Tue Nov 18, 2014 3:52 am

readers vs writers in nil

Postby acr » Tue Nov 18, 2014 4:04 am

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;
}

User avatar
Giovanni
Site Admin
Posts: 13528
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 861 times
Been thanked: 743 times
Contact:

Re: readers vs writers in nil

Postby Giovanni » Tue Nov 18, 2014 8:27 am

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

acr
Posts: 14
Joined: Tue Nov 18, 2014 3:52 am

Re: readers vs writers in nil

Postby acr » Wed Nov 19, 2014 12:16 pm

thank you Giovanni
exactly what i needed


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 1 guest