[Haskell-cafe] a question about concurrent haskell

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Sep 18 15:37:22 EDT 2008


Hello Manlio,

Thursday, September 18, 2008, 11:01:10 PM, you wrote:

you just need to handle it in a message-passing way. this type of
problem (serializing access to unique resource) is rather common, for
example it's used in GUI libs. std way is to create thread that will
do actual work in sequential way and provide channel for sending tasks
to this thread:

main = do
  chan <- newChan
  forkIO (forever$ getChan chan >>= id)
  ...

now you can put actions to chan and they will be executed sequentially


> Hi.

> I have a question about concurrent Haskell in GHC.

> Suppose I want to write a native pure Haskell PostgreSQL client.
> I have done this for Python (using Twisted):
> http://hg.mperillo.ath.cx/twisted/pglib/

> and I would like to do this in Haskell, as an exercise.

> The main problem is with multiple concurrent queries to the same 
> connection, from multiple threads.

> PostgreSQL supports multiple requests but it's better to execute only 
> one request at a time:
> http://www.postgresql.org/docs/8.3/interactive/protocol-flow.html#AEN73647


> In the Twisted version I queue all the requests, and every time a 
> request completes I call the callback associated with the request and 
> execute the next available request.

> But how do I solve this problem with concurrent Haskell?

> Suppose thread A execute a query, and while this query is still active,
> a thread B execute another query.

> I should suspend thread B (calling yield), but how do I resume it when
> the query executed by thread A completes?

> The GHC concurrent Haskell does not have a function to resume a given 
> thread (as found, as an example, in Lua).



> P.S.: another question.
> Why, in ghci, every time I call myThreadId, I get a different value?

> Prelude Control.Concurrent> myThreadId
> ThreadId 40
> Prelude Control.Concurrent> myThreadId
> ThreadId 41





> Thanks   Manlio Perillo
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list