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: [PATCHES][RFC] Fix a deadlock bug in static variable initialization


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

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