Re: [Haskell-cafe] Question about forkIO
Just to clarify, here is the sample haskell code that I am using - {-# LANGUAGE ForeignFunctionInterface #-} module Glue where import Foreign.C.String import qualified Control.Concurrent as CC funHaskell :: CString - IO Int funHaskell cstr = do putStrLn Haskell function called str - peekCString cstr CC.forkIO $ doForever str CC.threadDelay 200 return 0 doForever str = do putStrLn Hello World forever CC.threadDelay 100 doForever str foreign export stdcall funHaskell :: CString - IO Int When I call funHaskell from my C program, Hello World forever gets printed about twice - I think its because funHaskell waits for about 2 seconds before returning. However, once back in C land, the doForever function stops to execute. I was wondering if there is some setting that would allow the threads sparked to continue execute. Regards, Kashyap On Thu, Feb 28, 2013 at 4:39 PM, C K Kashyap ckkash...@gmail.com wrote: Hi All, Say I have a haskell function 'f' that does a forkIO and starts an action a. I create a DLL of this haskell code and inovke f from C. Can I expect the a to continue to run once f has returned to C? Regards, Kashyap ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about forkIO
On Thu, Feb 28, 2013 at 6:09 AM, C K Kashyap ckkash...@gmail.com wrote: Say I have a haskell function 'f' that does a forkIO and starts an action a. I create a DLL of this haskell code and inovke f from C. Can I expect the a to continue to run once f has returned to C? While you're off in C the I/O manager and garbage collector are suspended. Many C programs are not prepared to deal with the side effects of their operation, such as being interrupted by timer signals; moreover, it is not possible to have multiple handlers at the OS level for a signal, and C programs may want to use the signal handlers themselves. -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about forkIO
Quoth C K Kashyap ckkash...@gmail.com, ... Say I have a haskell function 'f' that does a forkIO and starts an action a. I create a DLL of this haskell code and inovke f from C. Can I expect the a to continue to run once f has returned to C? Once control returns to f's caller, outside of the Haskell runtime, then there isn't any way to dispatch IO threads - that's done by the runtime, so it can happen only while executing in the runtime. I am not a forkIO expert, that's just how it appears to me from my limited understanding of how they work. For extra credit - do the old IO threads resume if you call 'f' again, so you'd have more each time? (I don't know!) Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Question about forkIO
Hey Donn .. thanks, it turns out that threads do resume!!! This is how I got my gmail stuff working. I only have a doubt if the TCP keep/alive stuff continues to happen or not Regards, Kashyap On Thu, Feb 28, 2013 at 9:07 PM, Donn Cave d...@avvanta.com wrote: Quoth C K Kashyap ckkash...@gmail.com, ... Say I have a haskell function 'f' that does a forkIO and starts an action a. I create a DLL of this haskell code and inovke f from C. Can I expect the a to continue to run once f has returned to C? Once control returns to f's caller, outside of the Haskell runtime, then there isn't any way to dispatch IO threads - that's done by the runtime, so it can happen only while executing in the runtime. I am not a forkIO expert, that's just how it appears to me from my limited understanding of how they work. For extra credit - do the old IO threads resume if you call 'f' again, so you'd have more each time? (I don't know!) Donn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe