[Mono-bugs] [Bug 366441] New: Regex class is not threadsafe

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 1 21:48:43 EST 2008


           Summary: Regex class is not threadsafe
           Product: Mono: Class Libraries
           Version: SVN
          Platform: i686
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: tum at veridicus.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Field Engineer

The Regex class, after construction should be threadsafe as the state machine
should be readonly after construction.  For some reason, the Regex class is not
threadsafe.  A temporary fix is to protect the instance methods of the Regex
class such as Regex.Match with a lock but this is not ideal.

The following program is a test case:

using System;
using System.Threading;
using System.Text.RegularExpressions;

public class Test
        protected static Regex c_Regex = new Regex
                @"(ANS_TIME_POSITION\=)([0-9\.]+)", RegexOptions.IgnoreCase

        private static void Run()
                string s;
                Match match;

                s = "ANS_TIME_POSITION=100.0";

                while (true)
                        match = c_Regex.Match(s);

                        if (!match.Success)
                                Console.WriteLine("ERROR 1");

                        if (match.Groups[2].Value != "100.0")
                                Console.WriteLine("ERROR 2");

        public static void Main()
                Thread thread1, thread2;

                thread1 = new Thread(Run);

                thread2 = new Thread(Run);

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list