[Mono-bugs] [Bug 587994] BigInteger.ModPow can get stuck in an infinite loop using up CPU resources

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Mar 15 07:58:58 EDT 2010



--- Comment #2 from Michael Wood <michaelw at dip.co.uk> 2010-03-15 11:58:57 UTC ---
We've been experimenting more and discovered it isn't a problem specific to a
random number or prime set.  After discovering a set of numbers that it
occurred using I found re-doing the method with those numbers did not cause the
infinite loop.  It appears to only occur when the system is at high CPU usage,
whether this is due to other Mod Pows being performed or not. Here is a simple
sample application where the effect occurs most of the time I run it (over 50%
CPU and the code hung on that method):

    class Program
        static void Main(string[] args)
            int num = 300;

            BigIntThread[] bigInts = new BigIntThread[num];

            for (int i = 0; i < num; i++)
                bigInts[i] = new BigIntThread(i);

            for (int i = 0; i < num; i++)

        public class BigIntThread
            BigInteger bigTwo;
            BigInteger bigRandom;
            BigInteger bigPrime;
            Thread t;
            int id;

            public BigIntThread(int id)
                this.id = id;
                bigTwo = BigInteger.Parse("2");

                bigRandom =

                bigPrime =
                t = new Thread(new ThreadStart(ModPow));

            public void Start()

            public void ModPow()
                Console.WriteLine(id + " started");
                BigInteger bigPower = bigTwo.ModPow(bigRandom, bigPrime);
                Console.WriteLine(id + " stopped");

Could this be attributed to the use of unsafe code within Mod Pow?  We've
changed our implementation to use a singleton for performing the ModPow
however, this effect still occurs when the system is busy and it being a
singleton means that it sticks for all subsequent threads that use the method.

It's a requirement for us to be running 500+ threads that could use Mod Pow in
a short time period.

(In reply to comment #1)
> Please provide a tiple of numbers that show this behavior.

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

More information about the mono-bugs mailing list