示例#1
0
        public void SendFramesToSecondSt(object obj)
        {
            _postFrames = (PostDataFromSecondBufWt)obj;

            _signalFromFirstSt.WaitOne();
            _sentFrames = _receivedFrames;
            _postFrames(_sentFrames);
            ConsoleHelper.WriteToConsole("буфер 2", "отправил кадры станции 2");
            _signalToSecondSt.Release();

            _signalFromFirstSt.WaitOne();

            if (SecondStation.frameIsMissed == true)
            {
                _sentFrames = _receivedFrames;
                _postFrames(_sentFrames);
                ConsoleHelper.WriteToConsole("буфер 2", "отправил кадры станции 2");
                _signalToSecondSt.Release();

                _signalFromFirstSt.WaitOne();
            }


            _sentFrames = _receivedFrames;
            _postFrames(_sentFrames);
            ConsoleHelper.WriteToConsole("буфер 2", "отправил кадры станции 2");
            _signalToSecondSt.Release();
        }
示例#2
0
        static void Main(string[] args)
        {
            ConsoleHelper.WriteToConsole("Главный поток", "");

            Semaphore connectionSem    = new Semaphore(1, 1);
            Semaphore disConnectionSem = new Semaphore(1, 1);
            Semaphore transmissionSem  = new Semaphore(1, 1);

            Semaphore firstStToSecondBuf  = new Semaphore(0, 1);
            Semaphore secondBufToSecondSt = new Semaphore(0, 1);
            Semaphore secondStToFirstSt   = new Semaphore(0, 1);

            Semaphore secondStToFirstBuf = new Semaphore(0, 1);
            Semaphore firstBufToFirstSt  = new Semaphore(0, 1);
            Semaphore firstStToSecondSt  = new Semaphore(0, 1);


            FirstStation firstStation = new FirstStation(ref firstStToSecondBuf, ref firstBufToFirstSt, ref secondStToFirstSt, ref firstStToSecondSt,
                                                         ref transmissionSem, ref connectionSem, ref disConnectionSem);
            FirstBuffer   firstBuffer   = new FirstBuffer(ref secondStToFirstBuf, ref firstBufToFirstSt);
            SecondStation secondStation = new SecondStation(ref secondBufToSecondSt, ref secondStToFirstBuf, ref firstStToSecondSt, ref secondStToFirstSt,
                                                            ref transmissionSem, ref connectionSem, ref disConnectionSem);
            SecondBuffer secondBuffer = new SecondBuffer(ref firstStToSecondBuf, ref secondBufToSecondSt);


            Thread firstThread  = new Thread(new ParameterizedThreadStart(firstStation.SendFramesToSecondBuf));
            Thread secondThread = new Thread(new ParameterizedThreadStart(secondBuffer.SendFramesToSecondSt));
            Thread thirdThread  = new Thread(new ParameterizedThreadStart(secondStation.SendReceiptToFirstSt));
            Thread forthThread  = new Thread(new ParameterizedThreadStart(secondStation.SendFramesToFirstBuf));
            Thread fifthThread  = new Thread(new ParameterizedThreadStart(firstBuffer.SendFramesToFirstSt));
            Thread sixthThread  = new Thread(new ParameterizedThreadStart(firstStation.SendReceiptToSecondSt));


            PostDataToSecondBufWt   postDataToSecondBufferWt = new PostDataToSecondBufWt(secondBuffer.ReceiveFrames);
            PostDataFromSecondBufWt postDataFromSecondBufWt  = new PostDataFromSecondBufWt(secondStation.ReceiveFrames);
            SecondStPostToFirstStWt postReceiptToFirstStWt   = new SecondStPostToFirstStWt(firstStation.ReceiveReceipt);


            PostDataToFirstBufWt    postDataToFirstBufferWt  = new PostDataToFirstBufWt(firstBuffer.ReceiveFrames);
            PostDataFromFirstBufWt  postDataFromFirstBufWt   = new PostDataFromFirstBufWt(firstStation.ReceiveFrames);
            FirstStPostToSecondStWt postReceiptToSecondtStWt = new FirstStPostToSecondStWt(secondStation.ReceiveReceipt);


            firstThread.Start(postDataToSecondBufferWt);
            secondThread.Start(postDataFromSecondBufWt);
            thirdThread.Start(postReceiptToFirstStWt);
            forthThread.Start(postDataToFirstBufferWt);
            fifthThread.Start(postDataFromFirstBufWt);
            sixthThread.Start(postReceiptToSecondtStWt);

            Console.ReadLine();
        }