[project @ 2003-01-25 15:54:51 by wolfgang] This commit fixes many bugs and limitations in the threaded RTS. There are still some issues remaining, though.
[project @ 2003-01-25 15:54:51 by wolfgang]
This commit fixes many bugs and limitations in the threaded RTS.
There are still some issues remaining, though.

The following bugs should have been fixed:

- [+] "safe" calls could cause crashes
- [+] yieldToReturningWorker/grabReturnCapability
    -     It used to deadlock.
- [+] couldn't wake blocked workers
    -     Calls into the RTS could go unanswered for a long time, and
          that includes ordinary callbacks in some circumstances.
- [+] couldn't block on an MVar and expect to be woken up by a signal
      handler
    -     Depending on the exact situation, the RTS shut down or
          blocked forever and ignored the signal.
- [+] The locking scheme in RtsAPI.c didn't work
- [+] run_thread label in wrong place (schedule())
- [+] Deadlock in GHC.Handle
    -     if a signal arrived at the wrong time, an mvar was never
          filled again
- [+] Signals delivered to the "wrong" thread were ignored or handled
      too late.

Issues:
*) If GC can move TSO objects (I don't know - can it?), then ghci
will occasionally crash when calling foreign functions, because the
parameters are stored on the TSO stack.

*) There is still a race condition lurking in the code
(both threaded and non-threaded RTS are affected):
If a signal arrives after the check for pending signals in
schedule(), but before the call to select() in awaitEvent(),
select() will be called anyway. The signal handler will be
executed much later than expected.

*) For Win32, GHC doesn't yet support non-blocking IO, so while a
thread is waiting for IO, no call-ins can happen. If the RTS is
blocked in awaitEvent, it uses a polling loop on Win32, so call-ins
should work (although the polling loop looks ugly).

*) Deadlock detection is disabled for the threaded rts, because I
don't know how to do it properly in the presence of foreign call-ins
from foreign threads.
This causes the tests conc031, conc033 and conc034 to fail.

*) "safe" is currently treated as "threadsafe". Implementing "safe" in
a way that blocks other Haskell threads is more difficult than was
thought at first. I think it could be done with a few additional lines
of code, but personally, I'm strongly in favour of abolishing the
distinction.

*) Running finalizers at program termination is inefficient - there
are two OS threads passing messages back and forth for every finalizer
that is run. Also (just as in the non-threaded case) the finalizers
are run in parallel to any remaining haskell threads and to any
foreign call-ins that might still happen.

spacekitteh/smcghc,gcampax/ghc,gridaphobe/ghc,christiaanb/ghc,holzensp/ghc,gcampax/ghc,GaloisInc/halvm-ghc,mfine/ghc,bitemyapp/ghc,lukexi/ghc,nathyong/microghc-ghc,urbanslug/ghc,elieux/ghc,sdiehl/ghc,vikraman/ghc,nathyong/microghc-ghc,ml9951/ghc,sdiehl/ghc,shlevy/ghc,mettekou/ghc,shlevy/ghc,siddhanathan/ghc,jstolarek/ghc,mettekou/ghc,acowley/ghc,tibbe/ghc,shlevy/ghc,shlevy/ghc,snoyberg/ghc,holzensp/ghc,olsner/ghc,snoyberg/ghc,christiaanb/ghc,nathyong/microghc-ghc,nkaretnikov/ghc,nushio3/ghc,nathyong/microghc-ghc,nkaretnikov/ghc,mfine/ghc,mcschroeder/ghc,da-x/ghc,snoyberg/ghc,TomMD/ghc,ghc-android/ghc,forked-upstream-packages-for-ghcjs/ghc,tjakway/ghcjvm,sgillespie/ghc,nkaretnikov/ghc,tibbe/ghc,mettekou/ghc,da-x/ghc,ml9951/ghc,vTurbine/ghc,frantisekfarka/ghc-dsi,forked-upstream-packages-for-ghcjs/ghc,jstolarek/ghc,wxwxwwxxx/ghc,forked-upstream-packages-for-ghcjs/ghc,snoyberg/ghc,nushio3/ghc,gridaphobe/ghc,anton-dessiatov/ghc,sgillespie/ghc,fmthoma/ghc,gridaphobe/ghc,TomMD/ghc,fmthoma/ghc,mcschroeder/ghc,shlevy/ghc,bitemyapp/ghc,mcschroeder/ghc,da-x/ghc,vikraman/ghc,GaloisInc/halvm-ghc,elieux/ghc,mfine/ghc,wxwxwwxxx/ghc,spacekitteh/smcghc,siddhanathan/ghc,bitemyapp/ghc,sgillespie/ghc,oldmanmike/ghc,frantisekfarka/ghc-dsi,ghc-android/ghc,elieux/ghc,AlexanderPankiv/ghc,gcampax/ghc,wxwxwwxxx/ghc,lukexi/ghc,vTurbine/ghc,da-x/ghc,nathyong/microghc-ghc,forked-upstream-packages-for-ghcjs/ghc,da-x/ghc,oldmanmike/ghc,ghc-android/ghc,mcschroeder/ghc,siddhanathan/ghc,mettekou/ghc,siddhanathan/ghc,AlexanderPankiv/ghc,anton-dessiatov/ghc,mfine/ghc,elieux/ghc,olsner/ghc,tjakway/ghcjvm,oldmanmike/ghc,oldmanmike/ghc,acowley/ghc,AlexanderPankiv/ghc,ghc-android/ghc,ml9951/ghc,shlevy/ghc,mfine/ghc,sgillespie/ghc,holzensp/ghc,green-haskell/ghc,urbanslug/ghc,sdiehl/ghc,ryantm/ghc,ezyang/ghc,green-haskell/ghc,ezyang/ghc,vikraman/ghc,holzensp/ghc,da-x/ghc,ezyang/ghc,forked-upstream-packages-for-ghcjs/ghc,fmthoma/ghc,sgillespie/ghc,nushio3/ghc,nkaretnikov/ghc,gridaphobe/ghc,elieux/ghc,mcschroeder/ghc,AlexanderPankiv/ghc,green-haskell/ghc,forked-upstream-packages-for-ghcjs/ghc,fmthoma/ghc,nkaretnikov/ghc,bitemyapp/ghc,mettekou/ghc,anton-dessiatov/ghc,TomMD/ghc,green-haskell/ghc,TomMD/ghc,shlevy/ghc,sdiehl/ghc,GaloisInc/halvm-ghc,oldmanmike/ghc,nathyong/microghc-ghc,TomMD/ghc,mfine/ghc,christiaanb/ghc,anton-dessiatov/ghc,wxwxwwxxx/ghc,jstolarek/ghc,forked-upstream-packages-for-ghcjs/ghc,mfine/ghc,frantisekfarka/ghc-dsi,olsner/ghc,urbanslug/ghc,gcampax/ghc,ryantm/ghc,jstolarek/ghc,frantisekfarka/ghc-dsi,sgillespie/ghc,siddhanathan/ghc,vikraman/ghc,ezyang/ghc,vTurbine/ghc,siddhanathan/ghc,green-haskell/ghc,vikraman/ghc,TomMD/ghc,oldmanmike/ghc,urbanslug/ghc,nushio3/ghc,frantisekfarka/ghc-dsi,ghc-android/ghc,vTurbine/ghc,tibbe/ghc,olsner/ghc,da-x/ghc,nathyong/microghc-ghc,mettekou/ghc,tjakway/ghcjvm,acowley/ghc,spacekitteh/smcghc,GaloisInc/halvm-ghc,AlexanderPankiv/ghc,nushio3/ghc,urbanslug/ghc,AlexanderPankiv/ghc,vikraman/ghc,ezyang/ghc,tjakway/ghcjvm,lukexi/ghc,ryantm/ghc,urbanslug/ghc,mcschroeder/ghc,nkaretnikov/ghc,tjakway/ghcjvm,acowley/ghc,wxwxwwxxx/ghc,nushio3/ghc,nkaretnikov/ghc,ezyang/ghc,fmthoma/ghc,gcampax/ghc,ml9951/ghc,vTurbine/ghc,gridaphobe/ghc,wxwxwwxxx/ghc,snoyberg/ghc,ryantm/ghc,gridaphobe/ghc,oldmanmike/ghc,tibbe/ghc,snoyberg/ghc,spacekitteh/smcghc,spacekitteh/smcghc,mettekou/ghc,tjakway/ghcjvm,acowley/ghc,fmthoma/ghc,GaloisInc/halvm-ghc,anton-dessiatov/ghc,nushio3/ghc,ml9951/ghc,elieux/ghc,siddhanathan/ghc,ezyang/ghc,sgillespie/ghc,GaloisInc/halvm-ghc,sdiehl/ghc,acowley/ghc,sdiehl/ghc,holzensp/ghc,olsner/ghc,bitemyapp/ghc,sdiehl/ghc,gcampax/ghc,ml9951/ghc,tjakway/ghcjvm,ghc-android/ghc,wxwxwwxxx/ghc,TomMD/ghc,vTurbine/ghc,christiaanb/ghc,snoyberg/ghc,vikraman/ghc,olsner/ghc,anton-dessiatov/ghc,AlexanderPankiv/ghc,gridaphobe/ghc,olsner/ghc,ghc-android/ghc,tibbe/ghc,mcschroeder/ghc,fmthoma/ghc,lukexi/ghc,christiaanb/ghc,christiaanb/ghc,GaloisInc/halvm-ghc,anton-dessiatov/ghc,christiaanb/ghc,ml9951/ghc,lukexi/ghc,jstolarek/ghc,vTurbine/ghc,ryantm/ghc,elieux/ghc,urbanslug/ghc,gcampax/ghc,acowley/ghc,ml9951/ghc