[PATCHES][RFC] Fix a deadlock bug in static variable initialization

Andrew Pinski pinskia@gmail.com
Fri Jun 8 21:48:00 GMT 2007


On 6/8/07, Doug Kwan (關振德) <dougkwan@google.com> wrote:
> Hi,
>
>     Attached here is patches to both gcc and libstdc++-v3 to fix a
> deadlock problem in function static variables. The patches have been
> applied to gcc-4.1.0 and tested on i486 with a full bootstrap. I've
> also test the trunk it is not stable enough to do a full bootstrap.
A couple comments about the patch:

+    node_size = (sizeof(skip_list_node_t)
+		 + sizeof(skip_list_node_t*) * (level + 1));
+
+    new_node = (skip_list_node_t*) malloc(node_size);
+    if (!new_node)
+      throw std::bad_alloc();
+
+    for (int i = 0; i <= level ; i++)
+      new_node->forward[i] = NULL;

Use calloc instead so you don't need to zero out the forward array.

+	if (rand() < RAND_MAX/2)

When _GLIBCXX_HOSTED is not true rand will not be declared so this is
not going to work also rand is not thread safe at all.

Style issues with function calls:
+	level = random_level(list->max_level);
That should be:
+	level = random_level (list->max_level);

Note the space between the function name and '('.

+// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd*
*-*-linux* alpha*-*-osf* } }
+// { dg-options "-pthreads" { target *-*-solaris* } }

You can use -pthread on solaris on the trunk (and 4.2.0) also so you
can just use the normal dg-options (it is also support on darwin now
too).

Thanks,
Andrew Pinski


More information about the Libstdc++ mailing list