Changeset 4461 for trunk/compiler

Show
Ignore:
Timestamp:
08/31/08 09:01:15 (4 months ago)
Author:
pmoura
Message:

Corrected a bug in the implementation of the threaded_once/1-2 built-in multi-threading predicates (use of detached threads could make the methods fail despite the success of the thread goals).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4460 r4461  
    76257625 
    76267626 
    7627 '$lgt_tr_threaded_individual_goal'(TGoal, Queue, thread_create('$lgt_mt_threaded_call'(TGoal, Queue), Id, [at_exit('$lgt_mt_threaded_exit_handler'(Id, Queue))]), Id, id(Id, TGoal, _)). 
     7627'$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, _)). 
    76287628 
    76297629 
     
    1315213152 
    1315313153 
     13154% '$lgt_mt_dispatch_goal'(+atom, +object_identifier, +object_identifier, @callable, @nonvar) 
     13155% 
     13156% creates a thread for proving a goal (this predicate is called from within categories) 
     13157 
     13158'$lgt_mt_dispatch_goal'(Option, Goal, This, Self, Tag) :- 
     13159    '$lgt_current_object_'(This, Queue, _, _, _, _, _, _, _, _, _, _, _) -> 
     13160    '$lgt_mt_dispatch_goal'(Option, Queue, Goal, This, Self, Tag). 
     13161 
     13162 
     13163 
     13164% '$lgt_mt_dispatch_goal'(+atom, +message_queue, @callable, +object_identifier, +object_identifier, @nonvar) 
     13165% 
     13166% creates a thread for proving a goal 
     13167 
     13168'$lgt_mt_dispatch_goal'(ignore, _, Goal, _, _, _) :- 
     13169    thread_create(catch(Goal, _, true), _, [detached(true)]). 
     13170 
     13171'$lgt_mt_dispatch_goal'(call, Queue, Goal, This, Self, Tag) :- 
     13172    thread_create('$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag), Id, []), 
     13173    % wait until the thread created for proving the goal is ready before proceeding: 
     13174    thread_get_message(Queue, '$lgt_non_det_ready'(Id)). 
     13175 
     13176'$lgt_mt_dispatch_goal'(once, Queue, Goal, This, Self, Tag) :- 
     13177    thread_create('$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag), Id, []), 
     13178    % wait until the thread created for proving the goal is ready before proceeding: 
     13179    thread_get_message(Queue, '$lgt_det_ready'(Id)). 
     13180 
     13181 
     13182 
    1315413183% '$lgt_mt_det_goal'(+atom, +callable, +object_identifier, +object_identifier, @nonvar) 
    1315513184% 
    1315613185% processes a deterministic message received by an object's message queue 
    1315713186 
    13158 '$lgt_mt_det_goal'(Return, Goal, This, Self, Tag) :- 
    13159     thread_self(DetId), 
    13160     thread_send_message(Return, '$lgt_thread_id'(once, Goal, This, Self, Tag, DetId)), 
     13187'$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag) :- 
     13188    thread_self(Id), 
     13189    thread_send_message(Queue, '$lgt_thread_id'(once, Goal, This, Self, Tag, Id)), 
    1316113190    % signal that the thread running the goal is ready: 
    13162     thread_send_message(Return, '$lgt_det_ready'(Goal, This, Self, Tag)), 
    13163     (   catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, DetId)), Flag = error)) -> 
    13164         (   var(Flag) -> 
    13165             thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, success, DetId)) 
     13191    thread_send_message(Queue, '$lgt_det_ready'(Id)), 
     13192    (   catch(Goal, Error, thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, Error, Id))) -> 
     13193        (   var(Error) -> 
     13194            thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, success, Id)) 
    1316613195        ;   % Goal generated an exception, which was already reported 
    1316713196            true 
    1316813197        ) 
    13169     ;   thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, failure, DetId)) 
     13198    ;   thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, failure, Id)) 
    1317013199    ). 
    1317113200 
     
    1317613205% processes a non-deterministic message received by an object's message queue 
    1317713206 
    13178 '$lgt_mt_non_det_goal'(Return, Goal, This, Self, Tag) :- 
    13179     thread_self(NonDetId), 
    13180     thread_send_message(Return, '$lgt_thread_id'(call, Goal, This, Self, Tag, NonDetId)), 
     13207'$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag) :- 
     13208    thread_self(Id), 
     13209    thread_send_message(Queue, '$lgt_thread_id'(call, Goal, This, Self, Tag, Id)), 
    1318113210    % signal that the thread running the goal is ready: 
    13182     thread_send_message(Return, '$lgt_non_det_ready'(Goal, This, Self, Tag)), 
    13183     (   catch(Goal, Error, (thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, Error, NonDetId)), Flag = error)), 
    13184         (   var(Flag) -> 
    13185             thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, success, NonDetId)), 
     13211    thread_send_message(Queue, '$lgt_non_det_ready'(Id)), 
     13212    (   catch(Goal, Error, thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, Error, Id))), 
     13213        (   var(Error) -> 
     13214            thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, success, Id)), 
    1318613215            thread_get_message(Message), 
    1318713216            (   Message == '$lgt_next' -> 
     
    1319213221            true 
    1319313222        ) 
    13194     ;   thread_send_message(Return, '$lgt_reply'(Goal, This, Self, Tag, failure, NonDetId)) 
    13195     ). 
    13196  
    13197  
    13198  
    13199 % '$lgt_mt_dispatch_goal'(+atom, +object_identifier, +object_identifier, @callable, @tag) 
    13200 % 
    13201 % creates a thread for proving a goal (this predicate is called from within categories) 
    13202  
    13203 '$lgt_mt_dispatch_goal'(Option, Goal, This, Self, Tag) :- 
    13204     '$lgt_current_object_'(This, Queue, _, _, _, _, _, _, _, _, _, _, _) -> 
    13205     '$lgt_mt_dispatch_goal'(Option, Queue, Goal, This, Self, Tag). 
    13206  
    13207  
    13208  
    13209 % '$lgt_mt_dispatch_goal'(+atom, +message_queue, @callable, +object_identifier, +object_identifier, @tag) 
    13210 % 
    13211 % creates a thread for proving a goal 
    13212  
    13213 '$lgt_mt_dispatch_goal'(ignore, _, Goal, _, _, _) :- 
    13214     thread_create(catch(Goal, _, true), _, [detached(true)]). 
    13215  
    13216 '$lgt_mt_dispatch_goal'(call, Queue, Goal, This, Self, Tag) :- 
    13217     thread_create('$lgt_mt_non_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(false)]), 
    13218     % wait until the thread created for proving the goal is ready before proceeding: 
    13219     thread_get_message(Queue, '$lgt_non_det_ready'(Goal, This, Self, Tag)). 
    13220  
    13221 '$lgt_mt_dispatch_goal'(once, Queue, Goal, This, Self, Tag) :- 
    13222     thread_create('$lgt_mt_det_goal'(Queue, Goal, This, Self, Tag), _, [detached(false)]), 
    13223     % wait until the thread created for proving the goal is ready before proceeding: 
    13224     thread_get_message(Queue, '$lgt_det_ready'(Goal, This, Self, Tag)). 
     13223    ;   % no (more) solutions 
     13224        thread_send_message(Queue, '$lgt_reply'(Goal, This, Self, Tag, failure, Id)) 
     13225    ). 
    1322513226 
    1322613227 
     
    1331913320'$lgt_mt_threaded_call'(Goal, Queue) :- 
    1332013321    thread_self(Id), 
    13321     (   Goal -> 
     13322    (   call(Goal) -> 
    1332213323        thread_send_message(Queue, '$lgt_result'(Id, true(Goal))) 
    1332313324    ;   thread_send_message(Queue, '$lgt_result'(Id, false)) 
     
    1332613327 
    1332713328 
    13328 % '$lgt_mt_threaded_exit_handler'(@nonvar, +message_queue_identifier) 
     13329% '$lgt_mt_exit_handler'(@nonvar, +message_queue_identifier) 
    1332913330% 
    1333013331% error handler for threaded/1 individual thread calls; an error generated  
     
    1333313334% the worker thread 
    1333413335 
    13335 '$lgt_mt_threaded_exit_handler'(Id, Queue) :- 
     13336'$lgt_mt_exit_handler'(Id, Queue) :- 
    1333613337    thread_property(Id, status(exception(Error))), 
    1333713338    catch(thread_send_message(Queue, '$lgt_result'(Id, exception(Error))), _, thread_detach(Id)).