Threads in the new ISO C Standard from 2011
Threads in the new ISO C Standard from 2011
Threads in the new ISO C Standard from 2011
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
A Simplified Example<br />
Consider <strong>the</strong> follow<strong>in</strong>g example code (also orig<strong>in</strong>ally <strong>from</strong> L<strong>in</strong>ux)<br />
list_t* head;<br />
<strong>in</strong>t b;<br />
void <strong>in</strong>sert(<strong>in</strong>t a)<br />
{<br />
list_t* p = kmalloc(sizeof *p, GFP_KERNEL);<br />
}<br />
sp<strong>in</strong>_lock(&m);<br />
p->a = 1;<br />
p->next = head;<br />
rcu_assign_po<strong>in</strong>ter(head, p);<br />
sp<strong>in</strong>_unlock(&m);<br />
void first(void)<br />
{<br />
list_t* q = rcu_dereference(head);<br />
}<br />
return q->a + b;<br />
The use of rcu_dereference() must be done with<strong>in</strong> an<br />
rcu_read_lock() / rcu_read_unlock() — not seen <strong>in</strong> this<br />
example.<br />
Jonas Skeppstedt (js@cs.lth.se) Lecture 6 2013 39 / 70