transient-haskell / transient

A full stack, reactive architecture for general purpose programming. Algebraic and monadically composable primitives for concurrency, parallelism, event handling, transactions, multithreading, Web, and distributed computing with complete de-inversion of control (No callbacks, no blocking, pure state)
MIT License
630 stars 28 forks source link

threads primitive does not work as expected with logging #56

Closed harendra-kumar closed 4 years ago

harendra-kumar commented 7 years ago

Consider this program:

main = keep $ restore $ do
     r <- logged $ threads 3 $ choose [1..10 :: Int]
     logged $ liftIO $ print ("A",r)
     suspend ()
     logged $ liftIO $ print ("B",r)

This does not perform full 10 iterations.

agocorona commented 7 years ago

restoreassumes that suspend saved info for all the work units. But suspend exit before finishing all the threads. It must not exit when there are alternative thread waiting.

agocorona commented 4 years ago

The non-deterministic execution of transient precludes a way to assure that all the possible threads (or executions of the same threads) have passed trough the suspend point, It can not guarantee it. if However we detect that no threads remain active using the threadBlockedInMVarOperationexception used in collect that would imply that some computations would never suspend when some thread remain active waiting for some event. This is not desirable. Therefore this may be left as is, with all these caveats.

That is not because threads n but it makes things more apparent.