[Haskell-cafe] Re: Bound threads
Simon Marlow
simonmar at microsoft.com
Mon Feb 28 10:53:18 EST 2005
On 26 February 2005 12:14, Marcin 'Qrczak' Kowalczyk wrote:
> Wolfgang Thaller <wolfgang.thaller at gmx.net> writes:
>
>>> Since the main thread is bound, and unbound threads are never
>>> executed on an OS thread which has some Haskell thread bound, this
>>> would imply that when the main thread spawns a Haskell thread and
>>> they synchronize a lot with each other using MVars, the
>>> synchronization needs OS-thread synchronization - the threads will
>>> not execute on a the same OS thread.
>>
>> Correct.
>
> Is it important which thread executes Haskell code (I bet no) and
> unsafe foreign calls (I don't know)? If not, couldn't the same OS
> thread execute code of both threads until a safe foreign call is made?
Actually in a bound thread, *all* foreign calls must be made using the
correct OS thread, not just the safe ones. So your scheme would involve
a context switch at every foreign call, which would end up being rather
expensive. It's certainly a legitimate implementation, but I suspect
not one that would lead to good performance.
Cheers,
Simon
More information about the Haskell-Cafe
mailing list