darcs patch: forkChild, waitForChild, parIO, timeout

Einar Karttunen ekarttun at cs.helsinki.fi
Wed Nov 1 04:26:12 EST 2006


On 01.11 01:25, Peter Simons wrote:
> +	-- ** Child Threads
> +	ChildId,		-- opaque: ChildId a = Child ThreadId (MVar a)
> +	childId,		-- :: Child a -> ThreadId
> +	forkChild,		-- :: Monoid a => IO a -> IO (Child a)
> +	activeChild,		-- :: Child a -> IO Bool
> +	waitForChild,		-- :: Child a -> IO a

This makes it hard to have a manager thread that sits over a pool of
children and watches them. I think we could look at Erlang for the API
- it is one of the few languages which make it easy to handle pools
of child threads and restart handlers watching over them.

The proposed API makes it hard to manage a dynamically sized pool
of threads in an efficient fashion.


> +	-- ** Parallel Execution
> +	parIO,			-- :: Monoid a => IO a -> IO a -> IO a

Nice :-)

> +	-- ** Timeouts
> +	Timeout,		-- Timeout = Int

Better have a type like MicroSecond or Second that conveys
the meaning.

> +	timeout,		-- :: Timeout -> IO a -> IO (Maybe a)

The implementation is actually non-optimal and spawns
too many threads for the common case - I would propose
something like:

http://happs.org/HAppS/src/HAppS/Util/TimeOut.hs

instead which gives programmer the control to choose
between performance and blocking FFI calls.

- Einar Karttinen


More information about the Libraries mailing list