Re[Haskell-cafe] [2]: Threading and FFI

Yves Parès limestrael at gmail.com
Thu Feb 18 02:46:30 EST 2010


Thank you all.

But there are two things that remain obscure:
First, there is my situation: int the main thread, I call to some C
functions binded through FFI. All of them are marked 'unsafe', except one,
which is internally supposed to make pauses with 'usleep'.
I then execute in another haskell thread (with forkIO) some pure haskell
actions.
I then compile with the threaded RTS, and let at run the default behaviour
which is to use one core.

Question 1) What happens to the "unsafe" C functions? I that simply that the
threaded RTS is unable to prevent them from blocking haskell threads (which
in my case is a problem only for the function which pauses, since other C
calls are fast)? Or they could provoke a hazardous issue, so I have to mark
all the C functions as "safe" (which will be much slower) because ?

Question 2) In the Control.Concurrent documentation, I understood that
forkIO creates unbound threads whereas forkOS creates bound threads, but
what is not very clear is: when does GHC threaded runtime launches as bound
instead of unbound if this one has been started with forkIO? When it detects
the thread calls to a C function? When it detects it calls to a "safe" C
function (*)? When it detects another thread calls to a (safe) C function
(which is my case)?

(*) according to documentation it would be this case. However as I said my C
calls are done in the MAIN thread. The other thread just executes casual
haskell operations, however it is not blocked, which makes me think that
even if I launch it with forkIO, it is launched as an bound thread.


Bulat Ziganshin-2 wrote:
> 
> Hello Yves,
> 
> Thursday, February 18, 2010, 2:10:42 AM, you wrote:
> 
>> Okay! So under UNIX, haskell threaded runtime uses pthreads, if I well
>> understood.
> 
> not exactly. it still uses lightweight (green) threads, but starts
> additional OS threads as required to keep N haskell threads running.
> it's very smart
> 
> 
>> To sum up, in order to achieve what I want, I have no other choice than
>> compiling with '-threading' and importing as 'safe' the functions which
>> can
>> make a 'sleep'.
> 
>> Thanks!
> 


-----
Yves Parès

Live long and prosper
-- 
View this message in context: http://old.nabble.com/Threading-and-FFI-tp27611528p27635260.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list