basic threading

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

basic threading

Michael Easter
hi again everyone,

I am giving a tech talk soon, and aspire to show an example from Chapter 28
of RWH on the STM monad.

My example is just a watered down version of the "transfer wealth" example
in the book.  However it is
single threaded.

Q: is there an "easy" example of illustrating 2 threads that do something
(trivial is fine)? I believe that the book constructs a
thread library/manager of sorts but I wonder if there is something easier.

Though I'm not sure how to square this with my example, for now I'd love to
see an example of starting up
2 threads that do something and block until a keystroke is entered in the
terminal.

My apologies if this is too vague or too much "can you do my homework?" !

thanks
Michael

--
----------------------
Michael Easter
http://codetojoy.blogspot.com: Putting the thrill back in blog

http://youtube.com/ocitv -> Fun people doing serious software engineering
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090304/3fd091d8/attachment.htm
Reply | Threaded
Open this post in threaded view
|

basic threading

Thomas Davie

On 4 Mar 2009, at 13:33, Michael Easter wrote:

>
> hi again everyone,
>
> I am giving a tech talk soon, and aspire to show an example from  
> Chapter 28 of RWH on the STM monad.
>
> My example is just a watered down version of the "transfer wealth"  
> example in the book.  However it is
> single threaded.
>
> Q: is there an "easy" example of illustrating 2 threads that do  
> something (trivial is fine)? I believe that the book constructs a
> thread library/manager of sorts but I wonder if there is something  
> easier.
>
> Though I'm not sure how to square this with my example, for now I'd  
> love to see an example of starting up
> 2 threads that do something and block until a keystroke is entered  
> in the terminal.
>
> My apologies if this is too vague or too much "can you do my  
> homework?" !

Certainly, here's a nice one:

map _ [] = []
map f (x:xs) = f x : map f xs

parMap _ [] = []
parMap f (x:xs) = let fx = f x in fx `pseq` fx : map f xs

I realise this isn't what you expected ? it's not the STM monad ? but  
it *is* basic threading, far more basic, and far nicer than firing up  
monads and communication between threads.

Bob
Reply | Threaded
Open this post in threaded view
|

basic threading

Henk-Jan van Tuyl
In reply to this post by Michael Easter
On Wed, 04 Mar 2009 13:33:37 +0100, Michael Easter <[hidden email]>  
wrote:

> I am giving a tech talk soon, and aspire to show an example from Chapter  
> 28
> of RWH on the STM monad.
>
> My example is just a watered down version of the "transfer wealth"  
> example
> in the book.  However it is
> single threaded.
>
> Q: is there an "easy" example of illustrating 2 threads that do something
> (trivial is fine)? I believe that the book constructs a
> thread library/manager of sorts but I wonder if there is something  
> easier.
>
> Though I'm not sure how to square this with my example, for now I'd love  
> to
> see an example of starting up
> 2 threads that do something and block until a keystroke is entered in the
> terminal.
>


The page
   http://www.haskell.org/haskellwiki/Concurrency_demos
links to several examples of concurrency; maybe you are also interested in  
parallelism:
   http://groups.google.com/group/fa.haskell/browse_thread/thread/2aa4252637b50e0a

Regards,
Henk-Jan van Tuyl


--
http://functor.bamikanarie.com
http://Van.Tuyl.eu/
--




--