Difference between revisions of "Talk:SantaClausProblem"

From HaskellWiki
Jump to navigation Jump to search
(I/O: You still need to use locks.)
 
(50 intermediate revisions by 20 users not shown)
Line 1: Line 1:
 
= Beautiful concurrency =
 
= Beautiful concurrency =
   
I am writing a chapter for a book called "Beautiful code", edited by Greg Wilson. My [http://research.microsoft.com/~simonpj/tmp/beautiful.ps draft chapter] is about Software Transactional Memory in Haskell.
+
I have written a chapter for a book called "Beautiful code", edited by Greg Wilson. The chapter is a tutorial about Software Transactional Memory in Haskell. The book is aimed at a general audience of programmers, <em>not</em> Haskell geeks, so I have tried to explain everything necessary as I go along.
   
  +
You can find the paper itself, and the code download [http://research.microsoft.com/~simonpj/papers/stm here]. This Wiki talk-page is a place to contribute any post-publication thoughts or observations about the paper, if you wish.
I would welcome any comments or questions you have on the paper, or constructive suggestions for improving it; the more concrete the better.
 
 
The book is aimed at a general audience of programmers, <em>not</em> Haskell geeks, so I have tried to explain everything necessary as I go along. So if you are not a Haskell expert, your input would be particularly valuable to me.
 
 
You can email me directly (simonpj@microsoft.com), or add Wiki talk notes below.
 
   
 
----------
 
----------
Line 13: Line 9:
 
[[User:Simonpj|Simonpj]] 14:26, 22 December 2006 (UTC) To add a note, begin with four tilde signs <nowiki>~~~~</nowiki>; the Wiki will fill in your user name and date.
 
[[User:Simonpj|Simonpj]] 14:26, 22 December 2006 (UTC) To add a note, begin with four tilde signs <nowiki>~~~~</nowiki>; the Wiki will fill in your user name and date.
   
  +
[[User:Croach|Croach]] 17:10, 21 February 2007 (UTC)I just wanted to mention that it appears there is a small typo in the example code on page 2 of the paper. In the code you have a synchronized method called "withdraw" which you use again in the non-synchronized "deposit" method, only here you call the "withdraw" method "withdrawn". By the way, absolutely wonderful paper. I've been trying to learn everything I can about both Haskell and STM in the past few months and not only did this paper greatly increase my knowledge of STM, but it also helped increase my understanding of the basics of Haskell, which I already assumed I had a good grasp on. So, thank you for this work, it was an absolute joy to read.
----------
 
 
[[User:ArthurVanLeeuwen|ArthurVanLeeuwen]] 16:25, 22 December 2006 (UTC) There's a couple of typos in the paper as it is now. More importantly, the footnote on page 2 has (hGetLine h "hello") where it should state (hPutStr h "hello").
 
 
[[User:NeilMitchell|Neil Mitchell]] 16:28, 22 December 2006 (UTC) Sect 1, Para 2. If we want to write parallel program[s] - missing s.
 
 
 
[[User:Steven807|Steven807]] 17:14, 22 December 2006 (UTC) There is no definition or description of '''check'''
 
 
[[User:Tibbe|Tibbe]] 18:33, 22 December 2006 (UTC); The footnote on page 2 now has a incorrectly capitalized T in hPutSTr.
 
 
[[User:Fanf|Fanf]] 18:51, 22 December 2006 (UTC) page 1 para 2 "as well shall see" should be "as we shall see"
 
 
[[User:Fanf|Fanf]] 18:51, 22 December 2006 (UTC) page 3 "a bit like *t in C" should be "a bit like t* in C" since t is a type
 
 
[[User:Garious|Garious]] 18:56, 22 December 2006 (UTC) page 10 "at which point An elf" should be "at which point an elf"
 
 
[[User:Garious|Garious]] 18:58, 22 December 2006 (UTC) page 10 "Here, then is a possible" should be "Here then, is a possible"
 
 
[[User:Garious|Garious]] 19:16, 22 December 2006 (UTC) page 11 "Again, we define Group is declared" whaaa? maybe: "Group is declared as a data type with constructor MkGroup. MkGroup is passed the Group's capacity, and a TVar containing the number of current members and the Group's two Gates."
 
   
[[User:Garious|Garious]] 19:16, 22 December 2006 (UTC) page 11 "Creating a new Group is simply..." Is a process of three somewhat-abstract steps simple enough to say 'simply'? Instead, maybe show the code and let the reader think, "Hey, that's simple!"
 
   
[[User:Rycee|Rycee]] 20:46, 22 December 2006 (UTC) Page 4. You probably want to change "... the action a does ..." to "... the action act does ..."
+
[[User:CloudiDust|CloudiDust]] 16:24, 25 February 2007 (UTC) Thanks very much for this wonderful paper! I'm gaining a lot from it now as both a newbie to Haskell and one to concurrency. Here are the typos I have found:
   
  +
A. There is no "Int" but "int" in java. (I suppose they are java codes. :)
[[User:Rycee|Rycee]] 20:46, 22 December 2006 (UTC) Page 8. Typographic nitpick: The space after "i.e." looks wide, perhaps you forgot to write "i.e.\ " to force a regular (non sentence ending) space in LaTeX?
 
   
  +
B. In the code at the beginning of Page 3, there seems to be a semicolon missing after "to.unlock()".
[[User:MichalPalka|MichalPalka]] 22:32, 22 December 2006 (UTC) You could add a reference to SQL and triggers. They are similar in that it is programming with transations and seeing familiar names will make applied programmers feel more comfortable.
 
   
  +
C. In the Footnote 2 in Page 5, the sentence "That’s because Haskell supports currying, which can you can ..." seems to duplicate a "can", and there seems to be a right parenthesis missing after "e.g. [13]".
[[User:DavidHouse|DavidHouse]] 22:55, 22 December 2006 (UTC) Page 3, "That is, return v is a function that, when performed, does no side effects and returns v." Your use of 'that is' implies that you could deduce the fact that it does no side effects from the type signature just given, which isn't true. It's an auxiliary property of 'return'. Maybe just miss out the 'that is'.
 
   
  +
I'm now busy translating this paper into Chinese, and will feedback as often as I can. I wonder whether I can put my translation on the net and if so which license could I use? Many thanks again!
[[User:DavidHouse|DavidHouse]] 23:04, 22 December 2006 (UTC) Bottom of Page 4, "Then 'atomically act' grabs the lock, performs the action 'at',". Missing 'c' out of 'at'.
 
   
  +
[[User:TuukkaH|TuukkaH]] 22:07, 23 June 2007 (UTC) What can we say about the relation to message passing: [http://www.cs.otago.ac.nz/staffpriv/ok/santa/index.htm Solving the Santa Claus Problem in Erlang]?
[[User:DavidHouse|DavidHouse]] 23:23, 22 December 2006 (UTC) Page 5, "Then 'withdraw' is an STM action that adds amount to the balance in the account." 1) For consistency with the rest of the paper, it should be "Then 'withdraw account ammount'..." 2) withdraw subtracts, not adds, to the amount in the account.
 
   
  +
[[User:ChrisKuklewicz|ChrisKuklewicz]] 14:08, 25 June 2007 (UTC) In response to [[User:TuukkaH|TuukkaH]], I have posted code at [[Santa]] which is just a short adaptation of the Erlang to Haskell using just Chan and TChan (to get orElse).
[[User:DavidHouse|DavidHouse]] 23:40, 22 December 2006 (UTC) Page 9, you probably want to mention that ++ is string concatenation.
 
   
  +
[[User:TuukkaH|TuukkaH]] 14:33, 5 July 2007 (UTC) Thanks ChrisKuklewicz! I interpret that as Haskell supporting message passing better than Erlang, and it actually being a subconcept in STM too.
[[User:DavidHouse|DavidHouse]] 23:45, 22 December 2006 (UTC) Page 10, I would expect to see the type signatures for the Gate interface rewritten alongside their definitions.
 
   
  +
[[User:Alisezgin|Alisezgin]] 12:59, 31 December 2007 (UTC) it was a good read. i will have to look into a more detailed exposition pretty soon. but one quick question:
[[User:DavidHouse|DavidHouse]] 23:47, 22 December 2006 (UTC) Page 9/10, algebraic datatypes are a little weird for the non-initiated, especially with constructors that don't appear to do anything ("Where do you define MkGate?" etc.). You might want to liken them to C's structs, and explain the constructors as tags?
 
   
  +
from what i understand, an atomic block can only have side effects on stm variables. what if i want to have a block of io instructions (like launchmissiles) that need to be executed with no intervening instructions/threads, that is, atomically? this is of course assuming that rolling back will not be needed for this specific block. is this something that is fundamentally disallowed because it is poor programming practice? admittedly, i am no concurrent programmer so i am not familiar with what might come up while designing a concurrent system.
[[User:DavidHouse|DavidHouse]] 23:57, 22 December 2006 (UTC) Page 13, I don't think you sufficiently explain 'sequence'. You may wish to add a sentence along the lines of "'sequence' is a function that takes a list of IO actions and returns the action that, when executed, runs each of the actions you passed it in turn."
 
   
  +
[[User:Cjs|Cjs]] 08:12, 6 January 2009 (UTC) For I/O, you need to use locks. STM isn't a pancea. The reason the whole rollback thing works so well for STM in Haskell (it's a major problem in most non-Haskell STM implementations) is because the code run in the STM monad is pure (i.e., can't do I/O).
[[User:Dalejordan|Dalejordan]] 02:15, 23 December 2006 (UTC) For the sake of us newbs you might mention in Section 2.1 how all these actions ever get performed. Also, in your description of nTimes I think it would be clearer to say it creates a composite action that performs its argument action n times, rather than say it performs it (directly) n times, even though the value of n is not yet known. Another example of the "beauty" of first class actions (and recursion).
 

Latest revision as of 08:12, 6 January 2009

Beautiful concurrency

I have written a chapter for a book called "Beautiful code", edited by Greg Wilson. The chapter is a tutorial about Software Transactional Memory in Haskell. The book is aimed at a general audience of programmers, not Haskell geeks, so I have tried to explain everything necessary as I go along.

You can find the paper itself, and the code download here. This Wiki talk-page is a place to contribute any post-publication thoughts or observations about the paper, if you wish.


Simonpj 14:26, 22 December 2006 (UTC) To add a note, begin with four tilde signs ~~~~; the Wiki will fill in your user name and date.

Croach 17:10, 21 February 2007 (UTC)I just wanted to mention that it appears there is a small typo in the example code on page 2 of the paper. In the code you have a synchronized method called "withdraw" which you use again in the non-synchronized "deposit" method, only here you call the "withdraw" method "withdrawn". By the way, absolutely wonderful paper. I've been trying to learn everything I can about both Haskell and STM in the past few months and not only did this paper greatly increase my knowledge of STM, but it also helped increase my understanding of the basics of Haskell, which I already assumed I had a good grasp on. So, thank you for this work, it was an absolute joy to read.


CloudiDust 16:24, 25 February 2007 (UTC) Thanks very much for this wonderful paper! I'm gaining a lot from it now as both a newbie to Haskell and one to concurrency. Here are the typos I have found:

A. There is no "Int" but "int" in java. (I suppose they are java codes. :)

B. In the code at the beginning of Page 3, there seems to be a semicolon missing after "to.unlock()".

C. In the Footnote 2 in Page 5, the sentence "That’s because Haskell supports currying, which can you can ..." seems to duplicate a "can", and there seems to be a right parenthesis missing after "e.g. [13]".

I'm now busy translating this paper into Chinese, and will feedback as often as I can. I wonder whether I can put my translation on the net and if so which license could I use? Many thanks again!

TuukkaH 22:07, 23 June 2007 (UTC) What can we say about the relation to message passing: Solving the Santa Claus Problem in Erlang?

ChrisKuklewicz 14:08, 25 June 2007 (UTC) In response to TuukkaH, I have posted code at Santa which is just a short adaptation of the Erlang to Haskell using just Chan and TChan (to get orElse).

TuukkaH 14:33, 5 July 2007 (UTC) Thanks ChrisKuklewicz! I interpret that as Haskell supporting message passing better than Erlang, and it actually being a subconcept in STM too.

Alisezgin 12:59, 31 December 2007 (UTC) it was a good read. i will have to look into a more detailed exposition pretty soon. but one quick question:

from what i understand, an atomic block can only have side effects on stm variables. what if i want to have a block of io instructions (like launchmissiles) that need to be executed with no intervening instructions/threads, that is, atomically? this is of course assuming that rolling back will not be needed for this specific block. is this something that is fundamentally disallowed because it is poor programming practice? admittedly, i am no concurrent programmer so i am not familiar with what might come up while designing a concurrent system.

Cjs 08:12, 6 January 2009 (UTC) For I/O, you need to use locks. STM isn't a pancea. The reason the whole rollback thing works so well for STM in Haskell (it's a major problem in most non-Haskell STM implementations) is because the code run in the STM monad is pure (i.e., can't do I/O).