Re: bug: unstable myThreadId in GHC 6.6.1

2009-04-11 Thread Bertram Felgenhauer
Bulat Ziganshin wrote:
 Hello glasgow-haskell-users,
 
 i've looked for this bug in Trac but don't found anything. so:
 
 startGUI action = runInBoundThread $ do
   unsafeInitGUIForThreadedRTS
   myThreadId = writeIORef guiThread
   action = widgetShowAll
   mainGUI
 
 guiThread  =  unsafePerformIO$ newIORef$ error undefined GUI::guiThread
 
 
 Later in the same thread i ask for myThreadId and get different value.

What does same thread mean? I'll risk a guess.

mainGUI is a safe foreign call that executes a loop on the C side;
all future actions that you see and consider to be in the same thread
are actually callbacks from C to Haskell. But in GHC's RTS, a new
Haskell thread is created for each such callback, with a new thread id.
So myThreadId returns varying numbers, leading to the effect that you
described.

So it's not a bug, although it should be better documented.

It's not possible for the RTS to track which Haskell thread a callback
was originally registered from (at best it could remember which thread
created the original wrapper), and in any case that thread may be dead
already, or running Haskell code at the time the callback comes, so I
think that the current behaviour is quite sane.

regards,

Bertram
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re[2]: bug: unstable myThreadId in GHC 6.6.1

2009-04-11 Thread Bulat Ziganshin
Hello Bertram,

Saturday, April 11, 2009, 8:09:46 PM, you wrote:

 What does same thread mean? I'll risk a guess.

well, that's possible - i'll ask on gtk2hs list too

currently, i believe that mainGUI just runs endless loop processing
queue of GUI events

-- 
Best regards,
 Bulatmailto:bulat.zigans...@gmail.com

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users