This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Observation about hash-table.


On Fri, 2004-05-07 at 20:09, Dhruv Matani wrote:
> Hello everyone,
> 	I noticed that the hash-table uses chaining for its purposes. However,
> insertion is not thread-safe, but can be made so quite easily IMHO. Now,
> when the pointers for the vector and the link node are being set the
> following should ensure safety:
> 
> struct node;
> vector<node*> vpn(bucket_size);
> 
> void insert(const_ref value)
> {
> 	int bkt = //Bucket number.
> 	node* current = new node(value);
> 	node* tmp = current;
> 	atomic_exchange_after_deref(current, &vpn[bkt]);
> 	tmp->next = current;
> }
> 
> 
> Should this do the trick, or is something wrong?

Which I just realized is not as simple as I initially thought, because
the hash-table inserts values within a bucket in sorted order, as
opposed to just a stack like insertion as I initially thought :-(


> 
-- 
        -Dhruv Matani.
http://www.geocities.com/dhruvbird/

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]