[Haskell-cafe] a question about concurrent haskell

Manlio Perillo manlio_perillo at libero.it
Thu Sep 18 15:01:10 EDT 2008


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):

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:

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

More information about the Haskell-Cafe mailing list