readEVar (EVar id rn ref1)= freeThreads $ do
     liftIO $ atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n+1,n'+1)
     r <- parallel $ atomically $ do
                r <- peekTChan ref1
----                return ()               !> "peekTChan executed"
                (n,n') <- readTVar rn  -- !> "readtvar rn"
--                return ()              !> ("rn",n)
                if n'> 1 then do
                           writeTVar rn (n,n'-1)
                           return r
                         else do
                           readTChan ref1
                           writeTVar rn (n,n)
                           return r

     case r of
        SDone -> empty
        SMore x -> return x
        SLast x -> return x
        SError e -> liftIO $ do
            atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n-1,n'-1)
            myThreadId >>= killThread
            error $ "readEVar: "++ show e

-- |  update the EVar and execute all readEVar blocks with "last in-first out" priority
--
readEVar (EVar id rn ref1)= freeThreads $ do
     liftIO $ atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n+1,n'+1)
     r <- parallel $ atomically $ do
                r <- peekTChan ref1
----                return ()               !> "peekTChan executed"
                (n,n') <- readTVar rn  -- !> "readtvar rn"
--                return ()              !> ("rn",n)
                if n'> 1 then do
                           writeTVar rn (n,n'-1)
                           return r
                         else do
                           readTChan ref1
                           writeTVar rn (n,n)
                           return r

     case r of
        SDone -> empty
        SMore x -> return x
        SLast x -> return x
        SError e -> liftIO $ do
            atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n-1,n'-1)
            myThreadId >>= killThread
            error $ "readEVar: "++ show e

-- |  update the EVar and execute all readEVar blocks with "last in-first out" priority
--
readEVar (EVar id rn ref1)= freeThreads $ do
     liftIO $ atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n+1,n'+1)
     r <- parallel $ atomically $ do
                r <- peekTChan ref1
----                return ()               !> "peekTChan executed"
                (n,n') <- readTVar rn  -- !> "readtvar rn"
--                return ()              !> ("rn",n)
                if n'> 1 then do
                           writeTVar rn (n,n'-1)
                           return r
                         else do
                           readTChan ref1
                           writeTVar rn (n,n)
                           return r

     case r of
        SDone -> empty
        SMore x -> return x
        SLast x -> return x
        SError e -> liftIO $ do
            atomically $ readTVar rn >>= \(n,n') -> writeTVar rn $ (n-1,n'-1)
            myThreadId >>= killThread
            error $ "readEVar: "++ show e

-- |  update the EVar and execute all readEVar blocks with "last in-first out" priority
--