David,
Thanks. This makes sense and explains why we were seeing an inactive thread. It's useful to know that values can be passed from one sessions to the next via the stack - we hadn't fully appreciated that feature.
This behaviour with threads works well for what we are trying to do but there is still something we can't explain or see how to work around: after a loadState, when the running thread retrieves a referenced value, it no longer appears to pick up the latest value. I've provided an example that demonstrates this below. Is there a way for the thread to pick up assignments to the ref variable 'c' after the loadState?
Thanks, Phil
val c = ref 0;
open Thread;
fun run () : Thread.thread = let val cv = ConditionVar.conditionVar (); val m = Mutex.mutex ();
fun aux () = let open Time; val _ = ConditionVar.waitUntil (cv, m, now () + fromSeconds 1); in print (Int.toString (!c)); aux () end; in Thread.fork (aux, []) end;
val t = run (); (* prints 0 on standard output every second *)
c := 2; (* now prints 2 *)
PolyML.SaveState.saveState "test1.polydb"; (* save state with c = ref 2 *)
c := 3; (* now prints 3 *)
val t = (PolyML.SaveState.loadState "test1.polydb"; t); (* reload state *)
Thread.isActive t; (* thread still active *)
(* still printing 3, even though saved when c = ref 2 *)
c := 1; (* no effect, still prints 3 *)
David Matthews wrote:
Philip Clayton wrote:
Does anyone know what should happen to threads (created with Thread.Thread.fork) when PolyML.SaveState.loadState is performed? It appears that they are no longer reported as active but, despite this, carry on running. Is it up to the user to kill these before doing a loadState?
Phil, Threads continue running after loadState. However there is an issue with thread identifiers and I think this is what is causing the confusion.
Saved states are primarily intended to allow the state to be restored in a different session. Certain values, such as thread identifiers and stream identifiers, only have meaning within a particular session and aren't persistent. When they are saved and loaded, even within the same session, the link with the original object is broken. It is possible to "carry over" such a value within a session by passing it on the stack. Consider: val y = Thread.Mutex.mutex(); Thread.Mutex.lock y; val v = Thread.Thread.fork(fn () => Thread.Mutex.lock y, []); (* v now refers to a blocked but running thread. *) PolyML.SaveState.saveState "save";
val w = (PolyML.SaveState.loadState "save"; v);
After reloading Poly/ML reports:
Thread.Thread.isActive v;
val it = false : bool
Thread.Thread.isActive w;
val it = true : bool
There is a similar situation with streams. The reason it works this way is that there is no guarantee that the saved state loaded by loadState actually has been loaded in the same session it was saved in. To solve this would require (expensive) globally unique identifiers.
David
The information contained in this E-Mail and any subsequent correspondence is private and is intended solely for the intended recipient(s). The information in this communication may be confidential and/or legally privileged. Nothing in this e-mail is intended to conclude a contract on behalf of QinetiQ or make QinetiQ subject to any other legally binding commitments, unless the e-mail contains an express statement to the contrary or incorporates a formal Purchase Order.
For those other than the recipient any disclosure, copying, distribution, or any action taken or omitted to be taken in reliance on such information is prohibited and may be unlawful.
Emails and other electronic communication with QinetiQ may be monitored and recorded for business purposes including security, audit and archival purposes. Any response to this email indicates consent to this.
Telephone calls to QinetiQ may be monitored or recorded for quality control, security and other business purposes.
QinetiQ Limited Registered in England & Wales: Company Number:3796233 Registered office: 85 Buckingham Gate, London SW1E 6PD, United Kingdom Trading address: Cody Technology Park, Cody Building, Ively Road, Farnborough, Hampshire, GU14 0LX, United Kingdom http://www.qinetiq.com/home/notices/legal.html