I have followed the following webpage:
http://www.1024cores.net/home/lock-free-algorithms/reader-writer-problem/improved-lock-free-seqlock
the source is like following:
struct data_t
{
int seq; // sequence number
int data [1024]; // user data
};
struct seqlock_t
{
data_t* current;
data_t pool [16]; // 16 user objects are held
};
seqlock_t sl;
The structure is quite simple, what confuses me is the following:
data_t* d0 = sl.current; // load-consume
int idx = (sl.current - sl.pool + 1) % 16;
data_t* d = &sl.pool[idx];
The sl.current
is a pointer, sl.pool
is? What current - pool can achieve?
in c language
view, how should I explain this statement?
int idx = (sl.current - sl.pool + 1) % 16;
Edit :
Thanks for all information , it help a lot !!! in my own coding style would use int idx = (sl.current - &[sl.pool[0]) + 1) % 16; now I know &(sl.pool[0]) is the same with sl.pool !!! I should figure it out , the following example , what I read before , showes pointer/array ....
void display(int *p)
{
int idx ;
printf("(%d)(%d)\n",*p,p[1]) ;
}
int main()
{
int i,Arr[10] ;
for(i=0;i<10;i++)
Arr[i] = i + 100;
display(Arr) ;
}
Yes , I can use display(Arr) and display(&Arr[0]) , they are the same ~!!