[cpp-threads] Review comments on N2176 WRT dependency ordering
Paul E. McKenney
paulmck at linux.vnet.ibm.com
Tue Apr 17 22:09:21 BST 2007
On Tue, Apr 17, 2007 at 02:59:11PM +0300, Peter Dimov wrote:
> Peter Dimov wrote:
>
> >Are they important enough? We can add a minimalistic index-based
> >primitive along the lines of:
> >
> >template<class T, class U> inline U* atomic_load_index( T const * pi,
> >U * base );
>
> Or maybe you had in mind the other kind of indexing that we can support by
> adding an offset argument to atomic_load_address (defaulted to 0)?
That might work in some cases. A common expandable-hash-table case
looks something like this:
struct foo {
int size;
struct bar *array[0]; /* or [1] if no zero-length arrays */
};
struct foo *head = NULL;
int current_index;
- Creation of table
spin_lock(&mylock);
p = (struct foo *)malloc(sizeof(*p) + N * sizeof(struct bar *));
if (p == NULL) {
die();
}
p->size = N;
store_release_fence();
head = p;
spin_unlock(&mylock);
- Addition of "current" element i
spin_lock(&mylock);
q = new struct bar;
/* initialize q */
if (head->array[i] != NULL) {
die();
}
head->array[i] = q;
store_release_fence();
current_index = i;
spin_unlock(&mylock);
- Accessing "current" element
p = atomic_load_address(head);
q = p->array[atomic_load_address(current_index)];
Unless I am misunderstanding your proposal, the two separate
atomic_load_address()es are needed in this case.
Thanx, Paul
More information about the cpp-threads
mailing list