Ejemplo n.º 1
0
    public static int RunComplexe()
    {
        CompteurPartage c = new CompteurPartage();

        Thread[] t = new Thread[NB_THREADS];
        for (int i = 0; i < NB_THREADS; i++)
        {
            t[i]      = new Thread(new ThreadStart(new ExoThread(c).MethodeConcRessourcePartagee));
            t[i].Name = $"Thread # {i}";
        }

        var sw = Stopwatch.StartNew();

        for (int i = 0; i < NB_THREADS; i++)
        {
            t[i].Start();
        }
        for (int i = 0; i < NB_THREADS; i++)
        {
            t[i].Join();
        }

        sw.Stop();

        Console.WriteLine($"Test exécuté avec {NB_THREADS} threads. Valeur : {c.Valeur}. Temps écoulé : {sw.ElapsedMilliseconds}");
        return(c.Valeur);
    }
Ejemplo n.º 2
0
 public ExoThread(CompteurPartage c)
 {
     this.c = c;
 }