diff -Nur vala-0.7.10.262-39688/ccode/Makefile.am vala-0.7.10.262-39688-613943fix/ccode/Makefile.am
--- vala-0.7.10.262-39688/ccode/Makefile.am	2010-03-24 10:09:22.000000000 +0200
+++ vala-0.7.10.262-39688-613943fix/ccode/Makefile.am	2010-03-26 11:37:02.000000000 +0200
@@ -53,6 +53,7 @@
 	valaccodenode.vala \
 	valaccodeoncesection.vala \
 	valaccodeparenthesizedexpression.vala \
+	valaccoderawc.vala \
 	valaccodereturnstatement.vala \
 	valaccodestatement.vala \
 	valaccodestruct.vala \
diff -Nur vala-0.7.10.262-39688/ccode/valaccoderawc.vala vala-0.7.10.262-39688-613943fix/ccode/valaccoderawc.vala
--- vala-0.7.10.262-39688/ccode/valaccoderawc.vala	1970-01-01 02:00:00.000000000 +0200
+++ vala-0.7.10.262-39688-613943fix/ccode/valaccoderawc.vala	2010-03-26 11:36:52.000000000 +0200
@@ -0,0 +1,41 @@
+/* valaccodecomment.vala
+ *
+ * Copyright (C) 2006  Jürg Billeter
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ *
+ * Author:
+ * 	Jukka-Pekka Iivonen <jp0409@jippii.fi>
+ */
+
+using GLib;
+
+/**
+ * Represents a raw C code block to be attached in the generated C code.
+ */
+public class Vala.CCodeRawC : CCodeNode {
+	/**
+	 * The text content of the comment.
+	 */
+	public string text { get; set; }
+	
+	public CCodeRawC (string _text) {
+		text = _text;
+	}
+	
+	public override void write (CCodeWriter writer) {
+		writer.write_string (text);
+	}
+}
diff -Nur vala-0.7.10.262-39688/codegen/valaccodebasemodule.vala vala-0.7.10.262-39688-613943fix/codegen/valaccodebasemodule.vala
--- vala-0.7.10.262-39688/codegen/valaccodebasemodule.vala	2010-03-25 11:33:29.000000000 +0200
+++ vala-0.7.10.262-39688-613943fix/codegen/valaccodebasemodule.vala	2010-03-26 11:39:46.000000000 +0200
@@ -3575,13 +3575,29 @@
 		var cdecl = new CCodeDeclaration ("GRegex*");
 
 		var cname = regex_var.name + "regex_" + next_regex_id.to_string ();
+		if (this.next_regex_id == 0) {
+			var fun = new CCodeFunction ("_thread_safe_regex_init", "GRegex*");
+			fun.modifiers = CCodeModifiers.STATIC | CCodeModifiers.INLINE;
+			fun.add_parameter (new CCodeFormalParameter ("re", "GRegex**"));
+			fun.add_parameter (new CCodeFormalParameter ("pattern", "const gchar *"));
+			fun.add_parameter (new CCodeFormalParameter ("match_options", "GRegexMatchFlags"));
+			fun.block = new CCodeBlock ();
+			var regex_init_body = "\tif (g_once_init_enter ((volatile gsize*) re)) {\n"
+				+ "\t\tGRegex* val = g_regex_new (pattern, match_options, 0, NULL);\n"
+				+ "\t\tg_once_init_leave ((volatile gsize *) re, (gsize) val);\n"
+				+ "\t}\n"
+				+ "\treturn *re;";
+
+			var node = new CCodeRawC (regex_init_body);
+			fun.block.add_statement (node);
+			source_type_member_definition.append (fun);
+		}
 		this.next_regex_id++;
 
 		cdecl.add_declarator (new CCodeVariableDeclarator (cname + " = NULL"));
 		cdecl.modifiers = CCodeModifiers.STATIC;
 
-		var regex_const = new CCodeConstant ("(%s == NULL) ? (%s = g_regex_new (\"".printf (cname, cname)
-			+ re + "\", " + flags + ", 0, NULL)) : %s".printf (cname));
+		var regex_const = new CCodeConstant ("_thread_safe_regex_init (&%s, \"".printf (cname) + re + "\", " + flags + ")");
 
 		source_declarations.add_constant_declaration (cdecl);
 		expr.ccodenode = regex_const;
