STM.TChan vs. Chan ?

408 views
Skip to first unread message

Johannes Waldmann

unread,
May 21, 2013, 5:07:40 AM5/21/13
to parallel...@googlegroups.com
Hi.

Where could I read about the differences between

Control.Concurrent.Chan
Control.Concurrent.STM.TChan

and when should I use which?

Or is it no big deal - whenever the IO version would block
(reading an empty channel), the STM version does retry?

- Johannes.


Johannes Waldmann

unread,
May 21, 2013, 12:09:28 PM5/21/13
to parallel...@googlegroups.com
Johannes Waldmann <waldmann@...> writes:

> Control.Concurrent.Chan
> Control.Concurrent.STM.TChan

OK, this is partially answered by the docs -
and I was only asking since a search-engine directed me
to stm-2.2 haddocks which are somewhat terse.

Still, even stm-2.4 docs could be improved:

* readTChan :: TChan a -> STM a
Read the next value from the TChan.

* tryReadTChan :: TChan a -> STM (Maybe a)
A version of readTChan which does not retry

so I can infer only from tryReadTChan's doc
that readTChan could retry.

(of course, I can infer that also from the source)

- J.W.


Rick Richardson

unread,
Jun 4, 2013, 2:40:36 PM6/4/13
to parallel...@googlegroups.com, wald...@imn.htwk-leipzig.de
Beautiful Concurrency by SPJ is a good primer on this stuff. 

Johannes Waldmann

unread,
Jun 5, 2013, 4:04:19 AM6/5/13
to parallel...@googlegroups.com
Rick Richardson <rick.richardson@...> writes:

> Beautiful Concurrency by SPJ is a good primer on this stuff. 

I know. It does use TVar. I was asking about TChan.

For my purpose (of teaching),
I ended up showing and discussing the source in class

http://hackage.haskell.org/packages/archive/stm/2.4.2/doc/html/src/Control-Concurrent-STM-TQueue.html#readTQueue

- J.W.


Reply all
Reply to author
Forward
0 new messages