This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Observation about hash-table.
- From: Dhruv Matani <dhruvbird at gmx dot net>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: 07 May 2004 20:09:04 +0530
- Subject: Observation about hash-table.
- Organization:
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?
--
-Dhruv Matani.
http://www.geocities.com/dhruvbird/
Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html