RE: ThreadId should be Eq and Ord!!!!!

1999-08-20 Thread Julian Seward (Intl Vendor)


 PS: I forgot you also need a C function

 #include TSO.h/* in ghc/includes */
 
 cmp_thread( StgTSO *tso1, *tso2 ) {
   StgThreadID id1 = tso1-id;
   StgThreadId id2 = tso2-id;
 
   if (tso1  tso2) return (-1);
   if (tso1  tso2) return 1;
   return 0
 }

Shouldn't that be   

if (id1  id2) return (-1);
if (id1  id2) return 1;

?

J



ThreadId should be Eq and Ord!!!!!

1999-08-19 Thread George Russell

I asked for this months ago (it is after all documented) but nothing seems to have 
been done.
It is now extremely urgent that I sort this out if I want UniForM to work.  What am I 
to do??
Things are now sufficiently desperate that I will attempt to hack the GHC sources.



RE: ThreadId should be Eq and Ord!!!!!

1999-08-19 Thread Simon Peyton-Jones


 I asked for this months ago (it is after all documented) but 
 nothing seems to have been done.
 It is now extremely urgent that I sort this out if I want 
 UniForM to work.  What am I to do??
 Things are now sufficiently desperate that I will attempt to 
 hack the GHC sources.

George,

Try the module below.  It makes ThreadId an instance of Eq and Ord.

Simon


{-# OPTIONS -fglasgow-exts #-}

module Thread( cmpThread ) where

import PrelConc
import GlaExts

foreign import ccall "cmp_thread" unsafe cmp_thread :: Addr - Addr - Int
-- Returns -1, 0, 1

cmpThread :: ThreadId - ThreadId - Ordering
cmpThread (ThreadId t1) (ThreadId t2) 
  = case cmp_thread (unsafeCoerce# t1) (unsafeCoerce# t2) of
-1 - LT
0  - EQ
1  - GT

instance Eq ThreadId where
  t1 == t2 = case t1 `cmpThread` t2 of
EQ- True
other - False

instance Ord ThreadId where
  cmp = cmpThread