Question 1:
In the article to introduce RCU lock, he writes a publish-subscribe mechanism. But I have a question about rcu_assign_pointer(), in this article, he said:
1 p->a = 1;
2 p->b = 2;
3 p->c = 3;
4 rcu_assign_pointer(gp, p);
The rcu_assign_pointer() would publish the new structure, forcing both the compiler and the CPU to execute the assignment to gp after the assignments to the fields referenced by p.
But how could compiler and CPU know p has been assigned?For example, If I just initialise the p->a and p->b, then how compiler and CPU distinguish the two situation?
situation 1:
1 p->a = 1;
2 p->b = 2;
3 p->c = 3;
4 rcu_assign_pointer(gp, p);
situation 2:
1 p->a = 1;
2 p->b = 2;
3 rcu_assign_pointer(gp, p);
Question 2:
As for the read-side critical section, If there are continuous readers to read the data, should writer must wait for them or writer couldn't do the synchronise operation? If yes, reader will always read the older version?