Esempio n. 1
0
        //17 过程调用
        static async Task Worker17()
        {
            csp_chan <int, tuple <int, int> > csp = new csp_chan <int, tuple <int, int> >();

            generator.children children = new generator.children();
            children.go(async delegate()
            {
                for (int i = 0; i < 3; i++)
                {
                    csp_invoke_wrap <int> res = await csp.invoke(tuple.make(i, i));
                    Log($"csp 返回 {res.result}");
                    await generator.sleep(1000);
                }
                csp.close();
            });
            children.go(async delegate()
            {
                while (true)
                {
                    chan_state st = await generator.csp_wait(csp, async delegate(tuple <int, int> p)
                    {
                        Log($"recv {p}");
                        await generator.sleep(1000);
                        return(p.value1 + p.value2);
                    });
                    if (st == chan_state.closed)
                    {
                        Log($"csp 已关闭");
                        break;
                    }
                }
            });
            await children.wait_all();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            _strand = new shared_strand();
            _chan1  = channel <long> .make(_strand, 3);

            _chan2 = channel <long> .make(_strand, 0);

            _chan3 = channel <long> .make(_strand, -1);

            _csp = new csp_chan <long, long>(_strand);
            generator.go(_strand, Producer1);
            generator.go(_strand, Producer2);
            generator.go(_strand, Producer3);
            generator.go(_strand, Producer4);
            generator.go(_strand, Consumer).sync_wait();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            work_service work = new work_service();

            _strand = new work_strand(work);
            _chan1  = chan <long> .make(_strand, 3);

            _chan2 = chan <long> .make(_strand, 0);

            _chan3 = chan <long> .make(_strand, -1);

            _csp = new csp_chan <long, long>(_strand);
            generator.go(_strand, Producer1);
            generator.go(_strand, Producer2);
            generator.go(_strand, Producer3);
            generator.go(_strand, Producer4);
            generator.go(_strand, Consumer);
            generator.go(_strand, () => Producer5(generator.tgo(_strand, Consumer2)));
            work.run();
        }