src/Pure/Concurrent/future.ML
changeset 78681 38fe769658be
parent 78679 dc7455787a8e
child 78705 fde0b195cb7d
equal deleted inserted replaced
78680:61a6b4b81d6e 78681:38fe769658be
   193 fun cancel_now group = (*requires SYNCHRONIZED*)
   193 fun cancel_now group = (*requires SYNCHRONIZED*)
   194   let
   194   let
   195     val running = Task_Queue.cancel (! queue) group;
   195     val running = Task_Queue.cancel (! queue) group;
   196     val _ = running |> List.app (fn thread =>
   196     val _ = running |> List.app (fn thread =>
   197       if Isabelle_Thread.is_self thread then ()
   197       if Isabelle_Thread.is_self thread then ()
   198       else Isabelle_Thread.interrupt_unsynchronized thread);
   198       else Isabelle_Thread.interrupt_other thread);
   199   in running end;
   199   in running end;
   200 
   200 
   201 fun cancel_all () = (*requires SYNCHRONIZED*)
   201 fun cancel_all () = (*requires SYNCHRONIZED*)
   202   let
   202   let
   203     val (groups, threads) = Task_Queue.cancel_all (! queue);
   203     val (groups, threads) = Task_Queue.cancel_all (! queue);
   204     val _ = List.app Isabelle_Thread.interrupt_unsynchronized threads;
   204     val _ = List.app Isabelle_Thread.interrupt_other threads;
   205   in groups end;
   205   in groups end;
   206 
   206 
   207 fun cancel_later group = (*requires SYNCHRONIZED*)
   207 fun cancel_later group = (*requires SYNCHRONIZED*)
   208  (Unsynchronized.change canceled (insert Task_Queue.eq_group group);
   208  (Unsynchronized.change canceled (insert Task_Queue.eq_group group);
   209   broadcast scheduler_event);
   209   broadcast scheduler_event);
   448         val res =
   448         val res =
   449           if ok then
   449           if ok then
   450             Exn.capture (fn () =>
   450             Exn.capture (fn () =>
   451               Thread_Attributes.with_attributes atts (fn _ =>
   451               Thread_Attributes.with_attributes atts (fn _ =>
   452                 (Position.setmp_thread_data pos o Context.setmp_generic_context context) e ())) ()
   452                 (Position.setmp_thread_data pos o Context.setmp_generic_context context) e ())) ()
   453           else Exn.interrupt_exn;
   453           else Isabelle_Thread.interrupt_exn;
   454       in assign_result group result (identify_result pos res) end;
   454       in assign_result group result (identify_result pos res) end;
   455   in (result, job) end;
   455   in (result, job) end;
   456 
   456 
   457 
   457 
   458 (* fork *)
   458 (* fork *)
   643 
   643 
   644 fun promise_name name abort : 'a future =
   644 fun promise_name name abort : 'a future =
   645   let
   645   let
   646     val group = worker_subgroup ();
   646     val group = worker_subgroup ();
   647     val result = Single_Assignment.var "promise" : 'a result;
   647     val result = Single_Assignment.var "promise" : 'a result;
   648     fun assign () = assign_result group result Exn.interrupt_exn
   648     fun assign () = assign_result group result Isabelle_Thread.interrupt_exn
   649       handle Fail _ => true
   649       handle Fail _ => true
   650         | exn =>
   650         | exn =>
   651             if Exn.is_interrupt exn
   651             if Exn.is_interrupt exn
   652             then raise Fail "Concurrent attempt to fulfill promise"
   652             then raise Fail "Concurrent attempt to fulfill promise"
   653             else Exn.reraise exn;
   653             else Exn.reraise exn;
   663 fun fulfill_result (Future {promised = true, task, result}) res =
   663 fun fulfill_result (Future {promised = true, task, result}) res =
   664       let
   664       let
   665         val group = Task_Queue.group_of_task task;
   665         val group = Task_Queue.group_of_task task;
   666         val pos = Position.thread_data ();
   666         val pos = Position.thread_data ();
   667         fun job ok =
   667         fun job ok =
   668           assign_result group result (if ok then identify_result pos res else Exn.interrupt_exn);
   668           assign_result group result
       
   669             (if ok then identify_result pos res else Isabelle_Thread.interrupt_exn);
   669         val _ =
   670         val _ =
   670           Thread_Attributes.with_attributes Thread_Attributes.no_interrupts (fn _ =>
   671           Thread_Attributes.with_attributes Thread_Attributes.no_interrupts (fn _ =>
   671             let
   672             let
   672               val passive_job =
   673               val passive_job =
   673                 SYNCHRONIZED "fulfill_result" (fn () =>
   674                 SYNCHRONIZED "fulfill_result" (fn () =>