12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576openOrder_listtypeorder=ttypet={t:order;(* This strange dance with protect is to prevent the GC from collecting
values in the middle of an operation. *)mutableprotect:int;}letlock1t=t.protect<-t.protect+1letunlock1t=ift.protect=0thenforgett.t;t.protect<-t.protect-1letlock2t1t2=lock1t1;lock1t2letunlock2t1t2=unlock1t1;unlock1t2letforgett=ift.protect=0thenforgett.telset.protect<-t.protect-1letis_validt=lock1t;letresult=is_validt.tinunlock1t;resultletroot()=lett={t=root();protect=0}inGc.finaliseforgett;tletaftert=lock1t;lett'={t=aftert.t;protect=0}inGc.finaliseforgett';unlock1t;t'letbeforet=lock1t;lett'={t=beforet.t;protect=0}inGc.finaliseforgett';unlock1t;t'letsame_ordert1t2=lock2t1t2;letresult=same_ordert1.tt2.tinunlock2t1t2;resultletcomparet1t2=lock2t1t2;letresult=comparet1.tt2.tinunlock2t1t2;resultletcardinalt=lock1t;letresult=cardinalt.tinunlock1t;resultletunsafe_checktmsg=lock1t;unsafe_checkt.t("(Order_managed) "^msg);unlock1t