Esempio n. 1
0
        static void Test(int size)
        {
            Console.WriteLine("\n------------------");
              Console.WriteLine("Testing Join of size " + size);
              Join j = Join.Create(size);

              Synchronous.Channel sync;
              j.Initialize(out sync);
              Asynchronous.Channel<int>[] asyncs = new Asynchronous.Channel<int>[size - 1];

              for (int i = 0; i < size - 1; i++) {
            j.Initialize(out asyncs[i]);

            asyncs[i](i);
            int _i = i;
            j.When(sync).And(asyncs[i]).Do(delegate(int k) {
              Debug.Assert(_i == k);
              Console.Write(k +" ,"); });
            sync();
              }
        }
Esempio n. 2
0
    public Phil(int id, Table Table)
    {
        this.id = id;
        this.Table = Table;
        Join j = Join.Create(1);
        j.Initialize(out GetALife);

        if (Table.synchronous)
            j.When(GetALife).Do(getalifeSync);
        else
            GetALife = () => ThreadPool.QueueUserWorkItem(async _ => { await Task.Yield(); await (getalifeAsync()); });

        rg = new Random(id); /* each phil get its own (thread unsafe) rg */
        pos = maxpos;
        state = State.Thinking;

    }