Changeset 4569 for trunk/compiler
- Timestamp:
- 11/05/08 10:43:48 (2 months ago)
- Files:
-
- 1 modified
-
trunk/compiler/logtalk.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/compiler/logtalk.pl
r4563 r4569 7808 7808 '$lgt_tr_threaded_call'((TGoal; TGoals), catch(ThreadedCall, '$lgt_terminated', fail)) :- 7809 7809 !, 7810 '$lgt_tr_threaded_or_call'((TGoal; TGoals), Queue, MTGoals, Ids,Results),7810 '$lgt_tr_threaded_or_call'((TGoal; TGoals), Queue, MTGoals, Results), 7811 7811 ThreadedCall = ( thread_self(Queue), 7812 7812 thread_send_message(Queue, '$lgt_master'), 7813 7813 MTGoals, 7814 '$lgt_mt_threaded_or_exit'( Ids,Results)7814 '$lgt_mt_threaded_or_exit'(Results) 7815 7815 ). 7816 7816 7817 7817 '$lgt_tr_threaded_call'((TGoal, TGoals), catch(ThreadedCall, '$lgt_terminated', fail)) :- 7818 7818 !, 7819 '$lgt_tr_threaded_and_call'((TGoal, TGoals), Queue, MTGoals, Ids,Results),7819 '$lgt_tr_threaded_and_call'((TGoal, TGoals), Queue, MTGoals, Results), 7820 7820 ThreadedCall = ( thread_self(Queue), 7821 7821 thread_send_message(Queue, '$lgt_master'), 7822 7822 MTGoals, 7823 '$lgt_mt_threaded_and_exit'( Ids,Results)7823 '$lgt_mt_threaded_and_exit'(Results) 7824 7824 ). 7825 7825 … … 7827 7827 7828 7828 7829 '$lgt_tr_threaded_or_call'((TGoal; TGoals), Queue, (MTGoal, MTGoals), [ Id| Ids], [Result| Results]) :-7830 !, 7831 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Id,Result),7832 '$lgt_tr_threaded_or_call'(TGoals, Queue, MTGoals, Ids,Results).7833 7834 '$lgt_tr_threaded_or_call'(TGoal, Queue, MTGoal, [ Id], [Result]) :-7835 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Id,Result).7836 7837 7838 '$lgt_tr_threaded_and_call'((TGoal, TGoals), Queue, (MTGoal, MTGoals), [ Id| Ids], [Result| Results]) :-7839 !, 7840 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Id,Result),7841 '$lgt_tr_threaded_and_call'(TGoals, Queue, MTGoals, Ids,Results).7842 7843 '$lgt_tr_threaded_and_call'(TGoal, Queue, MTGoal, [ Id], [Result]) :-7844 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Id,Result).7845 7846 7847 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, thread_create('$lgt_mt_threaded_call'(TGoal, Queue), Id,[at_exit('$lgt_mt_exit_handler'(Id, Queue))]), Id, id(Id, TGoal, _)).7829 '$lgt_tr_threaded_or_call'((TGoal; TGoals), Queue, (MTGoal, MTGoals), [Result| Results]) :- 7830 !, 7831 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Result), 7832 '$lgt_tr_threaded_or_call'(TGoals, Queue, MTGoals, Results). 7833 7834 '$lgt_tr_threaded_or_call'(TGoal, Queue, MTGoal, [Result]) :- 7835 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Result). 7836 7837 7838 '$lgt_tr_threaded_and_call'((TGoal, TGoals), Queue, (MTGoal, MTGoals), [Result| Results]) :- 7839 !, 7840 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Result), 7841 '$lgt_tr_threaded_and_call'(TGoals, Queue, MTGoals, Results). 7842 7843 '$lgt_tr_threaded_and_call'(TGoal, Queue, MTGoal, [Result]) :- 7844 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, MTGoal, Result). 7845 7846 7847 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, thread_create('$lgt_mt_threaded_call'(TGoal, Queue), [at_exit('$lgt_mt_exit_handler'(Id, Queue))]), Id, id(Id, TGoal, _)). 7848 7848 7849 7849 … … 13650 13650 13651 13651 13652 % '$lgt_mt_threaded_and_exit'(+list (thread_identifier), +list)13652 % '$lgt_mt_threaded_and_exit'(+list) 13653 13653 % 13654 13654 % retrieves the result of proving a conjunction of goals using a threaded/1 predicate call 13655 13655 % by collecting the individual thread results posted to the master thread message queue 13656 13656 13657 '$lgt_mt_threaded_and_exit'( Ids,Results) :-13657 '$lgt_mt_threaded_and_exit'(Results) :- 13658 13658 thread_get_message('$lgt_result'(Id, Result)), 13659 '$lgt_mt_threaded_and_exit'(Result, Id, Ids,Results).13660 13661 13662 '$lgt_mt_threaded_and_exit'(terminate, _, Ids,Results) :-13663 '$lgt_mt_threaded_call_cancel'( Ids,Results),13659 '$lgt_mt_threaded_and_exit'(Result, Id, Results). 13660 13661 13662 '$lgt_mt_threaded_and_exit'(terminate, _, Results) :- 13663 '$lgt_mt_threaded_call_cancel'(Results), 13664 13664 throw('$lgt_terminated'). 13665 13665 … … 13667 13667 % thread result that lead to the termination of the other threads 13668 13668 13669 '$lgt_mt_threaded_and_exit'(exception(Error), Id, Ids,Results) :-13669 '$lgt_mt_threaded_and_exit'(exception(Error), Id, Results) :- 13670 13670 '$lgt_mt_threaded_record_result'(Results, Id, exception(Error)), 13671 13671 ( Error == '$lgt_terminated' -> 13672 '$lgt_mt_threaded_and_exit'( Ids,Results)13673 ; '$lgt_mt_threaded_call_cancel'( Ids,Results),13672 '$lgt_mt_threaded_and_exit'(Results) 13673 ; '$lgt_mt_threaded_call_cancel'(Results), 13674 13674 throw(Error) 13675 13675 ). 13676 13676 13677 '$lgt_mt_threaded_and_exit'(true(TGoal), Id, Ids,Results) :-13677 '$lgt_mt_threaded_and_exit'(true(TGoal), Id, Results) :- 13678 13678 '$lgt_mt_threaded_and_add_result'(Results, Id, TGoal, Continue), 13679 13679 ( Continue == false -> 13680 '$lgt_mt_threaded_call_join'( Ids)13681 ; '$lgt_mt_threaded_and_exit'( Ids,Results)13682 ). 13683 13684 '$lgt_mt_threaded_and_exit'(false, Id, Ids,Results) :-13680 '$lgt_mt_threaded_call_join'(Results) 13681 ; '$lgt_mt_threaded_and_exit'(Results) 13682 ). 13683 13684 '$lgt_mt_threaded_and_exit'(false, Id, Results) :- 13685 13685 '$lgt_mt_threaded_record_result'(Results, Id, false), 13686 '$lgt_mt_threaded_call_cancel'( Ids,Results),13686 '$lgt_mt_threaded_call_cancel'(Results), 13687 13687 fail. 13688 13688 … … 13720 13720 13721 13721 13722 % '$lgt_mt_threaded_or_exit'(+list (thread_identifier), +list)13722 % '$lgt_mt_threaded_or_exit'(+list) 13723 13723 % 13724 13724 % retrieves the result of proving a disjunction of goals using a threaded/1 predicate 13725 13725 % call by collecting the individual thread results posted to the call message queue 13726 13726 13727 '$lgt_mt_threaded_or_exit'( Ids,Results) :-13727 '$lgt_mt_threaded_or_exit'(Results) :- 13728 13728 thread_get_message('$lgt_result'(Id, Result)), 13729 '$lgt_mt_threaded_or_exit'(Result, Id, Ids,Results).13730 13731 13732 '$lgt_mt_threaded_or_exit'(terminate, _, Ids,Results) :-13733 '$lgt_mt_threaded_call_cancel'( Ids,Results),13729 '$lgt_mt_threaded_or_exit'(Result, Id, Results). 13730 13731 13732 '$lgt_mt_threaded_or_exit'(terminate, _, Results) :- 13733 '$lgt_mt_threaded_call_cancel'(Results), 13734 13734 throw('$lgt_terminated'). 13735 13735 … … 13737 13737 % thread result that lead to the termination of the other threads 13738 13738 13739 '$lgt_mt_threaded_or_exit'(exception(Error), Id, Ids,Results) :-13739 '$lgt_mt_threaded_or_exit'(exception(Error), Id, Results) :- 13740 13740 '$lgt_mt_threaded_record_result'(Results, Id, exception(Error)), 13741 13741 ( Error == '$lgt_terminated' -> 13742 '$lgt_mt_threaded_or_exit'( Ids,Results)13743 ; '$lgt_mt_threaded_call_cancel'( Ids,Results),13742 '$lgt_mt_threaded_or_exit'(Results) 13743 ; '$lgt_mt_threaded_call_cancel'(Results), 13744 13744 throw(Error) 13745 13745 ). 13746 13746 13747 '$lgt_mt_threaded_or_exit'(true(TGoal), Id, Ids,Results) :-13747 '$lgt_mt_threaded_or_exit'(true(TGoal), Id, Results) :- 13748 13748 '$lgt_mt_threaded_or_exit_unify'(Results, Id, TGoal), 13749 '$lgt_mt_threaded_call_cancel'( Ids,Results).13750 13751 '$lgt_mt_threaded_or_exit'(false, Id, Ids,Results) :-13749 '$lgt_mt_threaded_call_cancel'(Results). 13750 13751 '$lgt_mt_threaded_or_exit'(false, Id, Results) :- 13752 13752 '$lgt_mt_threaded_or_record_failure'(Results, Id, Continue), 13753 13753 ( Continue == true -> 13754 '$lgt_mt_threaded_or_exit'( Ids,Results)13754 '$lgt_mt_threaded_or_exit'(Results) 13755 13755 ; % all goals failed 13756 '$lgt_mt_threaded_call_join'( Ids),13756 '$lgt_mt_threaded_call_join'(Results), 13757 13757 fail 13758 13758 ). … … 13813 13813 13814 13814 13815 % '$lgt_mt_threaded_call_cancel'(+list (thread_identifier), +list)13815 % '$lgt_mt_threaded_call_cancel'(+list) 13816 13816 % 13817 13817 % aborts a threaded call by aborting and joining all individual threads; 13818 13818 % we must use catch/3 as some threads may already be terminated 13819 13819 13820 '$lgt_mt_threaded_call_cancel'( Ids,Results) :-13821 '$lgt_mt_threaded_call_abort'( Ids),13822 '$lgt_mt_threaded_call_join'( Ids,Results).13820 '$lgt_mt_threaded_call_cancel'(Results) :- 13821 '$lgt_mt_threaded_call_abort'(Results), 13822 '$lgt_mt_threaded_call_join'(Results). 13823 13823 13824 13824 13825 13825 '$lgt_mt_threaded_call_abort'([]). 13826 13826 13827 '$lgt_mt_threaded_call_abort'([ Id| Ids]) :-13827 '$lgt_mt_threaded_call_abort'([id(Id, _, _)| Ids]) :- 13828 13828 catch(thread_signal(Id, '$lgt_mt_abort_thread'(Id)), _, true), 13829 13829 '$lgt_mt_threaded_call_abort'(Ids). … … 13837 13837 13838 13838 13839 '$lgt_mt_threaded_call_join'([], []). 13840 13841 '$lgt_mt_threaded_call_join'([Id| Ids], [id(Id, _, Result)| Results]) :- 13839 13840 % '$lgt_mt_threaded_call_join'(+list) 13841 % 13842 % join all individual threads; we must use catch/3 as some threads may no longer exist 13843 13844 '$lgt_mt_threaded_call_join'([]). 13845 13846 '$lgt_mt_threaded_call_join'([id(Id, _, Result)| Results]) :- 13842 13847 ( var(Result) -> 13843 13848 thread_get_message('$lgt_result'(Id, _)) % don't leak thread results … … 13845 13850 ), 13846 13851 catch(thread_join(Id, _), _, true), 13847 '$lgt_mt_threaded_call_join'(Ids, Results). 13848 13849 13850 13851 % '$lgt_mt_threaded_call_join'(+list(thread_identifier)) 13852 % 13853 % join all individual threads; we must use catch/3 as some threads may no longer exist 13854 13855 '$lgt_mt_threaded_call_join'([]). 13856 13857 '$lgt_mt_threaded_call_join'([Id| Ids]) :- 13858 catch(thread_join(Id, _), _, true), 13859 '$lgt_mt_threaded_call_join'(Ids). 13852 '$lgt_mt_threaded_call_join'(Results). 13860 13853 13861 13854
