Ejemplo n.º 1
0
        public void ReaderWriterWithObserverEvent_WhenDeadlocked_Throws()
        {
            ReaderWriterWithObserverEventClass rw = new ReaderWriterWithObserverEventClass();
            Barrier barrier = new Barrier(2);

            rw.OnWrite += () =>
            {
                Task t = new Task(
                    () =>
                {
                    lock (rw)
                    {
                        barrier.SignalAndWait();
                        rw.Write(1);
                    }
                });
                t.Start();
                barrier.SignalAndWait();
                lock (rw)
                {
                }
            };

            rw.Write(100);

            //rw.Read( 100 );
        }
        public void ReaderWriterObserverEventTest()
        {
            ReaderWriterWithObserverEventClass rw = new ReaderWriterWithObserverEventClass();

            ManualResetEventSlim mrEvent = new ManualResetEventSlim(false);

            rw.OnWrite += mrEvent.Set;

            rw.Write(100);

            mrEvent.Wait();
        }
        public void ReaderWriterObserverEventTest()
        {
            ReaderWriterWithObserverEventClass rw = new ReaderWriterWithObserverEventClass();

            ManualResetEventSlim mrEvent = new ManualResetEventSlim( false );

            rw.OnWrite += mrEvent.Set;

            rw.Write( 100 );

            mrEvent.Wait();
        }
        public void ReaderWriterWithObserverEvent_WhenDeadlocked_Throws()
        {
            ReaderWriterWithObserverEventClass rw = new ReaderWriterWithObserverEventClass();
            Barrier barrier = new Barrier(2);

            rw.OnWrite += () =>
                              {
                                  Task t = new Task(
                                      () =>
                                      {
                                          lock (rw)
                                          {
                                              barrier.SignalAndWait();
                                              rw.Write(1);
                                          }
                                      });
                                  t.Start();
                                  barrier.SignalAndWait();
                                  lock (rw)
                                  {
                                  }
                              };

            rw.Write(100);

            //rw.Read( 100 );
        }