Changeset 4312
- Timestamp:
- 06/14/08 15:12:35 (4 months ago)
- Files:
-
- 1 modified
-
trunk/compiler/logtalk.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/compiler/logtalk.pl
r4306 r4312 13214 13214 ( Error == '$lgt_terminated' -> 13215 13215 '$lgt_mt_threaded_and_exit'(Ids, Results) 13216 ; '$lgt_mt_threaded_call_cancel'(Ids, Results , Id),13216 ; '$lgt_mt_threaded_call_cancel'(Ids, Results), 13217 13217 throw(Error) 13218 13218 ). … … 13222 13222 '$lgt_mt_threaded_and_add_result'(Results, Id, TGoal, Continue), 13223 13223 ( Continue == false -> 13224 '$lgt_mt_threaded_call_join'(Ids , Results)13224 '$lgt_mt_threaded_call_join'(Ids) 13225 13225 ; '$lgt_mt_threaded_and_exit'(Ids, Results) 13226 13226 ). … … 13228 13228 '$lgt_mt_threaded_and_exit'(false, Id, Ids, Results) :- 13229 13229 '$lgt_mt_threaded_record_result'(Results, Id, false), 13230 '$lgt_mt_threaded_call_cancel'(Ids, Results , Id),13230 '$lgt_mt_threaded_call_cancel'(Ids, Results), 13231 13231 fail. 13232 13232 … … 13285 13285 ( Error == '$lgt_terminated' -> 13286 13286 '$lgt_mt_threaded_or_exit'(Ids, Results) 13287 ; '$lgt_mt_threaded_call_cancel'(Ids, Results , Id),13287 ; '$lgt_mt_threaded_call_cancel'(Ids, Results), 13288 13288 throw(Error) 13289 13289 ). … … 13292 13292 thread_get_message('$lgt_result'(Id, TGoal)), 13293 13293 '$lgt_mt_threaded_record_result'(Results, Id, true), 13294 '$lgt_mt_threaded_call_cancel'(Ids, Results , Id),13294 '$lgt_mt_threaded_call_cancel'(Ids, Results), 13295 13295 '$lgt_mt_threaded_or_exit_unify'(Results, Id, TGoal). 13296 13296 … … 13300 13300 '$lgt_mt_threaded_or_exit'(Ids, Results) 13301 13301 ; % all goals failed 13302 '$lgt_mt_threaded_call_join'(Ids , Results),13302 '$lgt_mt_threaded_call_join'(Ids), 13303 13303 fail 13304 13304 ). … … 13332 13332 % records a thread goal failure and checks if all other thread goals have failed: 13333 13333 13334 '$lgt_mt_threaded_or_record_failure'([id(Id, _, fa il)| Results], Id, Continue) :-13334 '$lgt_mt_threaded_or_record_failure'([id(Id, _, false)| Results], Id, Continue) :- 13335 13335 !, 13336 13336 ( var(Continue) -> % we still don't know if there are any pending results … … 13339 13339 ). 13340 13340 13341 '$lgt_mt_threaded_or_record_failure'([id(_, _, Done)| Results], Id, Continue) :-13342 ( var( Done) ->13341 '$lgt_mt_threaded_or_record_failure'([id(_, _, Result)| Results], Id, Continue) :- 13342 ( var(Result) -> 13343 13343 Continue = true % we found a thread whose result is still pending 13344 13344 ; true % otherwise continue examining the remaining thread results … … 13349 13349 '$lgt_mt_threaded_or_continue'([], false). 13350 13350 13351 '$lgt_mt_threaded_or_continue'([id(_, _, Done)| Results], Continue) :-13352 ( var( Done) ->13351 '$lgt_mt_threaded_or_continue'([id(_, _, Result)| Results], Continue) :- 13352 ( var(Result) -> 13353 13353 % we found a thread whose result is still pending 13354 13354 Continue = true … … 13359 13359 13360 13360 13361 % '$lgt_mt_threaded_call_cancel'(+list(thread_identifier), +list , +thread_identifier)13361 % '$lgt_mt_threaded_call_cancel'(+list(thread_identifier), +list) 13362 13362 % 13363 13363 % aborts a threaded call by aborting and joining all individual threads; 13364 13364 % we must use catch/3 as some threads may already be terminated 13365 13366 '$lgt_mt_threaded_call_cancel'(Ids, Results, ProtectedId) :-13367 '$lgt_mt_threaded_call_abort'(Ids, ProtectedId),13368 '$lgt_mt_threaded_call_join'(Ids, Results).13369 13370 13371 '$lgt_mt_threaded_call_abort'([], _).13372 13373 '$lgt_mt_threaded_call_abort'([ProtectedId| Ids], ProtectedId) :-13374 !,13375 '$lgt_mt_threaded_call_abort'(Ids, ProtectedId).13376 13377 '$lgt_mt_threaded_call_abort'([Id| Ids], ProtectedId) :-13378 ( catch(thread_peek_message(Id, '$lgt_master'), _, fail) ->13379 catch(thread_send_message(Id, '$lgt_status'(_, terminate)), _, true)13380 ; catch(thread_signal(Id, '$lgt_mt_thread_abort'), _, true)13381 ),13382 '$lgt_mt_threaded_call_abort'(Ids, ProtectedId).13383 13384 13365 13385 13366 '$lgt_mt_threaded_call_cancel'(Ids, Results) :- … … 13402 13383 '$lgt_mt_threaded_call_join'([Id| Ids], [id(Id, _, Result)| Results]) :- 13403 13384 ( var(Result) -> 13385 % don't leak thread results 13404 13386 thread_get_message('$lgt_status'(Id, Result)), 13405 13387 ( Result == true -> … … 13416 13398 mutex_unlock_all, 13417 13399 throw('$lgt_terminated'). 13400 13401 13402 13403 % '$lgt_mt_threaded_call_join'(+list(thread_identifier)) 13404 % 13405 % join all individual threads; we must use catch/3 as some threads may no longer exist 13406 13407 '$lgt_mt_threaded_call_join'([]). 13408 13409 '$lgt_mt_threaded_call_join'([Id| Ids]) :- 13410 catch(thread_join(Id, _), _, true), 13411 '$lgt_mt_threaded_call_join'(Ids). 13418 13412 13419 13413
