Click here to Skip to main content
15,923,689 members
Home / Discussions / C#
   

C#

 
QuestionPlz help me Pin
dia 201022-May-10 22:04
dia 201022-May-10 22:04 
AnswerRe: Plz help me Pin
Abhinav S22-May-10 22:20
Abhinav S22-May-10 22:20 
Generalthis chunck of code have same results Pin
dia 201023-May-10 1:26
dia 201023-May-10 1:26 
AnswerRe: Plz help me Pin
Not Active23-May-10 3:38
mentorNot Active23-May-10 3:38 
Generalgetting ip address of client on server side Pin
dia 201023-May-10 18:53
dia 201023-May-10 18:53 
QuestionHow to include in installer Access Database 2003.? Pin
joynil22-May-10 17:51
joynil22-May-10 17:51 
AnswerRe: How to include in installer Access Database 2003.? Pin
PIEBALDconsult23-May-10 7:08
mvePIEBALDconsult23-May-10 7:08 
QuestionWhats iS THE Problem Of MY code in Monitor class For Resolve of Race Condition Pin
shahramkeyboard22-May-10 11:26
shahramkeyboard22-May-10 11:26 
hi my Code IS:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace RaceCondition
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string s=" ";


        Thread t1, t2;

        private void button1_Click(object sender, EventArgs e)
        {
            t1 = new Thread(f1);
            t2 = new Thread(f2);
            t1.Start();
            t2.Start();
            while (t1.IsAlive||t2.IsAlive)
            {
                Thread.Sleep(50);
            }
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i]=='n')
                {
                    listBox1.Items.Add("");
                }
                else
	            {
                    listBox1.Items[listBox1.Items.Count-1]+=s[i].ToString();
	            }
            }
        }

        Random r = new Random();
        void f1()
        {
            
            Thread.Sleep(r.Next(2));
            System.Threading.Monitor.Enter(s);
            for (int i = 1; i <= 100; i+=2)
            {

                Thread.Sleep(r.Next(2));
                s += 'n';
                Thread.Sleep(r.Next(2));
                s += "T1 ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                System.Threading.Monitor.Exit(s);
            }
            Thread.Sleep(r.Next(2));
        }

        void f2()
        {
            Thread.Sleep(r.Next(2));
            System.Threading.Monitor.Enter(s);
            for (int i = 2; i <= 100; i += 2)
            {

                Thread.Sleep(r.Next(2));
                s += 'n';
                Thread.Sleep(r.Next(2));
                s += "T2 ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                s += i.ToString() + "  ";
                Thread.Sleep(r.Next(2));
                System.Threading.Monitor.Exit(s);
            }
            Thread.Sleep(r.Next(2));
        }
    }
}


WHat is the problem of this code

I want to use Monitor TO Reslove Race Condition
AnswerRe: Whats iS THE Problem Of MY code in Monitor class For Resolve of Race Condition Pin
Luc Pattyn22-May-10 11:49
sitebuilderLuc Pattyn22-May-10 11:49 
Questionuse of ? and : [Solved] Pin
William Winner22-May-10 11:22
William Winner22-May-10 11:22 
AnswerRe: use of ? and : Pin
Pete O'Hanlon22-May-10 11:27
mvePete O'Hanlon22-May-10 11:27 
GeneralRe: use of ? and : Pin
William Winner22-May-10 11:30
William Winner22-May-10 11:30 
GeneralRe: use of ? and : Pin
Pete O'Hanlon22-May-10 11:33
mvePete O'Hanlon22-May-10 11:33 
GeneralRe: use of ? and : Pin
#realJSOP23-May-10 2:00
professional#realJSOP23-May-10 2:00 
AnswerRe: use of ? and : [Solved] Pin
DaveyM6923-May-10 1:20
professionalDaveyM6923-May-10 1:20 
Questionhelp to translate label from dll on C# Pin
kozzzak22-May-10 11:14
kozzzak22-May-10 11:14 
AnswerRe: help to translate label from dll on C# [modified] Pin
Luc Pattyn22-May-10 11:43
sitebuilderLuc Pattyn22-May-10 11:43 
QuestionPeterson Algoritm For many Process Pin
shahramkeyboard22-May-10 10:34
shahramkeyboard22-May-10 10:34 
AnswerRe: Peterson Algoritm For many Process Pin
Pete O'Hanlon22-May-10 10:45
mvePete O'Hanlon22-May-10 10:45 
GeneralRe: Peterson Algoritm For many Process Pin
shahramkeyboard22-May-10 11:27
shahramkeyboard22-May-10 11:27 
GeneralRe: Peterson Algoritm For many Process Pin
Pete O'Hanlon22-May-10 11:33
mvePete O'Hanlon22-May-10 11:33 
QuestionSimulation Of TSL instruction For Resolve of Race Condition Pin
shahramkeyboard22-May-10 10:25
shahramkeyboard22-May-10 10:25 
AnswerRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
Pete O'Hanlon22-May-10 10:44
mvePete O'Hanlon22-May-10 10:44 
GeneralRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
shahramkeyboard22-May-10 11:28
shahramkeyboard22-May-10 11:28 
GeneralRe: Simulation Of TSL instruction For Resolve of Race Condition Pin
Pete O'Hanlon22-May-10 11:38
mvePete O'Hanlon22-May-10 11:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.