This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCHES][RFC] Fix a deadlock bug in static variable initialization
- From: "Andrew Pinski" <pinskia at gmail dot com>
- To: "Doug Kwan (éæå)" <dougkwan at google dot com>
- Cc: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Fri, 8 Jun 2007 14:48:16 -0700
- Subject: Re: [PATCHES][RFC] Fix a deadlock bug in static variable initialization
- References: <498552560706081416x3a0d30lf2abee607b1bb00a@mail.gmail.com>
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