[Mono-list] Help with Threading

Loren Bandiera lorenb@mmgsecurity.com
Wed, 29 Sep 2004 12:27:37 -0400 (EDT)

I'm trying to do some work with threads but I'm not getting very far. I
took a step back and wrote a sample program which attempts to count to
100.  It creates a thread, increments a shared variable and then prints
the results.

My problem is that when I attempt to run this it works at first but then
it just stops running after the 72nd try.

I tried running it under Windows (w/ MS .NET Runtime v1.1) and it worked
as expected.  Possible Mono bug?  Maybe something on my Linux box is the
issue?  (NPTL maybe?)

Anyone got any ideas?


using System;
using System.Threading;

public class ThreadingTest {

        private int counter = 0;

        private void Count () {

                lock (this) {
                        Console.WriteLine (counter);


        public void Start () {

                for (int i = 0; i < 100; i++) {
                        Thread t = new Thread (new ThreadStart (Count));
                        t.Start ();


public class MyApplication {

        public static void Main () {

                ThreadingTest tt = new ThreadingTest ();
                tt.Start ();

Loren Bandiera, CISSP <lorenb@mmgsecurity.com>
MMG Security, Inc.