Changeset 4305

Show
Ignore:
Timestamp:
06/08/08 10:03:53 (4 months ago)
Author:
pmoura
Message:

Corrected a bug in the implementation of the built-in meta-predicate threaded/1 when canceling individual threads when one of them terminates with an exception or a failure.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4304 r4305  
    74097409% translates the argument of a call to the built-in predicate threaded/1 
    74107410 
    7411 '$lgt_tr_threaded_call'((TGoal; TGoals), ThreadedCall) :- 
     7411'$lgt_tr_threaded_call'((TGoal; TGoals), catch(ThreadedCall, '$lgt_terminated', fail)) :- 
    74127412    !, 
    74137413    '$lgt_tr_threaded_or_call'((TGoal; TGoals), Queue, MTGoals, Ids, Results), 
     
    74187418                    ). 
    74197419 
    7420 '$lgt_tr_threaded_call'((TGoal, TGoals), ThreadedCall) :- 
     7420'$lgt_tr_threaded_call'((TGoal, TGoals), catch(ThreadedCall, '$lgt_terminated', fail)) :- 
    74217421    !, 
    74227422    '$lgt_tr_threaded_and_call'((TGoal, TGoals), Queue, MTGoals, Ids, Results), 
     
    1320413204 
    1320513205'$lgt_mt_threaded_and_exit'(terminate, _, Ids, _) :- 
    13206     '$lgt_mt_threaded_call_cancel'(Ids). 
    13207  
    13208 '$lgt_mt_threaded_and_exit'(exception(Error), _, Ids, _) :- 
    13209     '$lgt_mt_threaded_call_cancel'(Ids, Error), 
    13210     throw(Error). 
     13206    '$lgt_mt_threaded_call_cancel'(Ids), 
     13207    throw('$lgt_terminated'). 
     13208 
     13209'$lgt_mt_threaded_and_exit'(exception(Error), Id, Ids, Results) :- 
     13210    (   Error == '$lgt_terminated' -> 
     13211        '$lgt_mt_threaded_and_exit'(Ids, Results) 
     13212    ;   '$lgt_mt_threaded_call_cancel'(Ids, Id), 
     13213        throw(Error) 
     13214    ). 
    1321113215 
    1321213216'$lgt_mt_threaded_and_exit'(true, Id, Ids, Results) :- 
     
    1321813222    ). 
    1321913223 
    13220 '$lgt_mt_threaded_and_exit'(false, _, Ids, _) :- 
    13221     '$lgt_mt_threaded_call_cancel'(Ids), 
     13224'$lgt_mt_threaded_and_exit'(false, Id, Ids, _) :- 
     13225    '$lgt_mt_threaded_call_cancel'(Ids, Id), 
    1322213226    fail. 
    1322313227 
     
    1326613270 
    1326713271'$lgt_mt_threaded_or_exit'(terminate, _, Ids, _) :- 
    13268     '$lgt_mt_threaded_call_cancel'(Ids). 
    13269  
    13270 '$lgt_mt_threaded_or_exit'(exception(Error), _, Ids, _) :- 
    13271     '$lgt_mt_threaded_call_cancel'(Ids, Error), 
    13272     throw(Error). 
     13272    '$lgt_mt_threaded_call_cancel'(Ids), 
     13273    throw('$lgt_terminated'). 
     13274 
     13275'$lgt_mt_threaded_or_exit'(exception(Error), Id, Ids, Results) :- 
     13276    (   Error == '$lgt_terminated' -> 
     13277        '$lgt_mt_threaded_or_exit'(Ids, Results) 
     13278    ;   '$lgt_mt_threaded_call_cancel'(Ids, Id), 
     13279        throw(Error) 
     13280    ). 
    1327313281 
    1327413282'$lgt_mt_threaded_or_exit'(true, Id, Ids, Results) :- 
    1327513283    thread_get_message('$lgt_result'(Id, TGoal)), 
    13276     '$lgt_mt_threaded_call_cancel'(Ids), 
     13284    '$lgt_mt_threaded_call_cancel'(Ids, Id), 
    1327713285    '$lgt_mt_threaded_or_exit_unify'(Results, Id, TGoal). 
    1327813286 
     
    1332913337 
    1333013338 
    13331 % '$lgt_mt_threaded_call_abort'(+list(thread_identifier)) 
     13339% '$lgt_mt_threaded_call_cancel'(+list(thread_identifier), thread_identifier) 
    1333213340% 
    1333313341% aborts a threaded call by aborting and joining all individual threads; 
    1333413342% we must use catch/3 as some threads may already be terminated 
     13343 
     13344'$lgt_mt_threaded_call_cancel'(Ids, ProtectedId) :- 
     13345    '$lgt_mt_threaded_call_abort'(Ids, ProtectedId), 
     13346    '$lgt_mt_threaded_call_join'(Ids). 
     13347 
     13348 
     13349'$lgt_mt_threaded_call_abort'([], _). 
     13350 
     13351'$lgt_mt_threaded_call_abort'([ProtectedId| Ids], ProtectedId) :- 
     13352    !, 
     13353    '$lgt_mt_threaded_call_abort'(Ids, ProtectedId). 
     13354 
     13355'$lgt_mt_threaded_call_abort'([Id| Ids], ProtectedId) :- 
     13356    (   catch(thread_peek_message(Id, '$lgt_master'), _, fail) -> 
     13357        catch(thread_send_message(Id, '$lgt_status'(_, terminate)), _, true) 
     13358    ;   catch(thread_signal(Id, '$lgt_mt_thread_abort'), _, true) 
     13359    ), 
     13360    '$lgt_mt_threaded_call_abort'(Ids, ProtectedId). 
     13361 
    1333513362 
    1333613363'$lgt_mt_threaded_call_cancel'(Ids) :- 
     
    1334413371    (   catch(thread_peek_message(Id, '$lgt_master'), _, fail) -> 
    1334513372        catch(thread_send_message(Id, '$lgt_status'(_, terminate)), _, true) 
    13346     ;   catch(thread_signal(Id, '$lgt_mt_thread_abort'(abort)), _, true) 
     13373    ;   catch(thread_signal(Id, '$lgt_mt_thread_abort'), _, true) 
    1334713374    ), 
    1334813375    '$lgt_mt_threaded_call_abort'(Ids). 
    13349  
    13350  
    13351 '$lgt_mt_threaded_call_cancel'(Ids, Error) :- 
    13352     '$lgt_mt_threaded_call_abort'(Ids, Error), 
    13353     '$lgt_mt_threaded_call_join'(Ids). 
    13354  
    13355  
    13356 '$lgt_mt_threaded_call_abort'([], _). 
    13357  
    13358 '$lgt_mt_threaded_call_abort'([Id| Ids], Error) :- 
    13359     (   catch(thread_peek_message(Id, '$lgt_master'), _, fail) -> 
    13360         catch(thread_send_message(Id, '$lgt_status'(_, terminate)), _, true) 
    13361     ;   catch(thread_signal(Id, '$lgt_mt_thread_abort'(Error)), _, true) 
    13362     ), 
    13363     '$lgt_mt_threaded_call_abort'(Ids, Error). 
    1336413376 
    1336513377 
     
    1337113383 
    1337213384 
    13373 '$lgt_mt_thread_abort'(Error) :- 
     13385'$lgt_mt_thread_abort' :- 
    1337413386    mutex_unlock_all, 
    13375     throw(Error). 
     13387    throw('$lgt_terminated'). 
    1337613388 
    1337713389 
  • trunk/RELEASE_NOTES.txt

    r4303 r4305  
    2222    Updated the Logtalk runtime error handler to test for non-instantiated  
    2323    exception terms. Thanks to Joerg Schuster for the bug report. 
     24 
     25    Corrected a bug in the implementation of the built-in meta-predicate  
     26    threaded/1 when canceling individual threads when one of them terminates  
     27    with an exception or a failure. 
    2428 
    2529    Added a new default compiler option, multifile_directive, to all config