From 74e4cc63610597bd434925d27482fc15f1695312 Mon Sep 17 00:00:00 2001 From: Jean-loup Gailly Date: Wed, 13 Jan 2010 01:06:02 +0100 Subject: [PATCH] Increment global hash atomically. --- uct/tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/uct/tree.c b/uct/tree.c index ebe3d0e..77cf9d4 100644 --- a/uct/tree.c +++ b/uct/tree.c @@ -18,6 +18,7 @@ #include "uct/tree.h" +/* This function may be called by multiple threads in parallel */ static struct tree_node * tree_init_node(struct tree *t, coord_t coord, int depth) { @@ -28,8 +29,8 @@ tree_init_node(struct tree *t, coord_t coord, int depth) } n->coord = coord; n->depth = depth; - static long c = 1000000; - n->hash = c++; + volatile static long c = 1000000; + n->hash = __sync_fetch_and_add(&c, 1); if (depth > t->max_depth) t->max_depth = depth; return n; -- 2.11.4.GIT