35 message_queue_create/2,
37 message_queue_property/2,
67 thread_set_defaults/1,
72 with_mutex/2], [
'$reinit_thread0'/0,
76:-
'$run_at_thread_start'/0
'$system_catch'/4
use_system_module(
'$_boot', [
80:-
'$do_error'/2
use_system_module(
'$_errors', []).
84 thread_initialization(
0),
95 throw(error(instantiation_error,
volatile(
P))).
100 '$do_volatile'(
G1,
M),
101 '$do_volatile'(
G2,
M).
103 '$current_module'(
M),
106'$do_volatile'(
P,
M)
:- dynamic(
M:P).
117 recorda(
'$thread_alias', [
0|main],
_),
120 '$no_threads',
recorda.
122 recorda(
'$thread_defaults', [
0,
0,
0, false, true],
_).
125 '$no_threads',
recorda.
129'$top_thread_goal'(
G,
Detached)
:-
131 (
Detached == true
-> '$detach_thread'(
Id)
; '$detach_thread'),
132 '$current_module'(
Module),
133 '$run_at_thread_start',
135 '$system_catch'((
G -> throw(
'$thread_finished'(true))
; throw(
'$thread_finished'(false))),
Module,
Exception,
'$close_thread'(
Exception,
Detached)),
139'$close_thread'(
Status,
_Detached)
:-
140 '$thread_zombie_self'(
Id0),
'$thread_zombie_self',
141 '$record_thread_status'(
Id0,
Status),
142 '$run_at_thread_exit'(
Id0),
143 '$erase_thread_info'(
Id0).
147'$record_thread_status'(
Id0,
Stat)
:- '$record_thread_status',
148 '$mk_tstatus_key'(
Id0,
Key),
151 Stat = '$thread_finished'(
Status)
->
154 recorda(
Key, exception(
Stat),
_)
166 '$thread_options'([detached(true)], [],
Stack,
Trail,
System,
Detached,
AtExit,
G0),
167 '$thread_new_tid'(
Id),
170 '$create_thread'(
Goal,
Stack,
Trail,
System,
Detached,
AtExit,
Id)
174 '$mk_tstatus_key'(
Id,
Key),
175 recorda(
Key, exception(resource_error(memory)),
_)
188 (
nonvar(
Id)
-> '$do_error'(uninstantiation_error(
Id),
G0)
; '$do_error' ),
189 '$thread_options'([], [],
Stack,
Trail,
System,
Detached,
AtExit,
G0),
190 '$thread_new_tid'(
Id),
193 '$create_thread'(
Goal,
Stack,
Trail,
System,
Detached,
AtExit,
Id)
197 '$mk_tstatus_key'(
Id,
Key),
198 recorda(
Key, exception(resource_error(memory)),
_)
247 (
nonvar(
Id)
-> '$do_error'(uninstantiation_error(
Id),
G0)
; '$do_error' ),
248 '$thread_options'(
Options,
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
G0),
249 '$thread_new_tid'(
Id),
251 '$record_alias_info'(
Id,
Alias),
253 '$create_thread'(
Goal,
Stack,
Trail,
System,
Detached,
AtExit,
Id)
257 '$mk_tstatus_key'(
Id,
Key),
258 recorda(
Key, exception(resource_error(memory)),
_)
261'$erase_thread_info'(
Id)
:-
265'$erase_thread_info'(
Id)
:-
266 recorded(
'$thread_exit_hook', [
Id|_],
R),
269'$erase_thread_info'(
_).
272'$thread_options'(
Opts,
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
G)
:-
273 strip_module(
Opts,
Mod,
LOpts),
277 '$do_error'(instantiation_error,
G)
281 '$do_error'(instantiation_error,
G)
285 '$do_error'(uninstantiation_error(
Mod),
G)
289 '$do_error'(instantiation_error,
G)
291 '$thread_options'(
LOpts,
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
Mod,
G)
294'$thread_options'([],
_,
Stack,
Trail,
System,
Detached,
AtExit,
_M,
_)
:-
295 recorded(
'$thread_defaults', [
DefaultStack,
DefaultTrail,
DefaultSystem,
DefaultDetached,
DefaultAtExit],
_),
296 (
var(
Stack)
-> Stack = DefaultStack; var ),
297 (
var(
Trail)
-> Trail = DefaultTrail; var ),
298 (
var(
System)
-> System = DefaultSystem; var ),
299 (
var(
Detached)
-> Detached = DefaultDetached; var ),
300 (
var(
AtExit)
-> AtExit = DefaultAtExit; var ).
301'$thread_options'([
Opt|Opts],
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
M,
G0)
:-
302 '$thread_option'(
Opt,
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
M,
G0),
303 '$thread_options'(
Opts,
Alias,
Stack,
Trail,
System,
Detached,
AtExit,
M,
G0).
305'$thread_option'(
Option,
_,
_,
_,
_,
_,
_,
_,
G0)
:- var(
Option),
var,
306 '$do_error'(instantiation_error,
G0).
307'$thread_option'(alias(
Alias),
Alias,
_,
_,
_,
_,
_,
_,
G0)
:- '$thread_option',
308 (
\+ atom(
Alias)
-> '$do_error'(type_error(atom,
Alias),
G0)
; '$do_error' ).
309'$thread_option'(stack(
Stack),
_,
Stack,
_,
_,
_,
_,
_,
G0)
:- '$thread_option',
310 (
\+ integer(
Stack)
-> '$do_error'(type_error(integer,
Stack),
G0)
; '$do_error' ).
311'$thread_option'(trail(
Trail),
_,
_,
Trail,
_,
_,
_,
_,
G0)
:- '$thread_option',
312 (
\+ integer(
Trail)
-> '$do_error'(type_error(integer,
Trail),
G0)
; '$do_error' ).
313'$thread_option'(system(
System),
_,
_,
_,
System,
_,
_,
_,
G0)
:- '$thread_option',
314 (
\+ integer(
System)
-> '$do_error'(type_error(integer,
System),
G0)
; '$do_error' ).
315'$thread_option'(detached(
Detached),
_,
_,
_,
_,
Detached,
_,
_,
G0)
:- '$thread_option',
316 (
Detached \== true,
Detached \== false
-> '$do_error'(domain_error(thread_option,
Detached+[true,false]),
G0)
; '$do_error' ).
317'$thread_option'(at_exit(
AtExit),
_,
_,
_,
_,
_,
AtExit,
_M,
G0)
:- '$thread_option',
318 (
\+ callable(
AtExit)
-> '$do_error'(type_error(callable,
AtExit),
G0)
; '$do_error' ).
320'$thread_option'(
_Option,
_,
_,
_,
_,
_,
_,
_,
_G0).
323'$record_alias_info'(
_,
Alias)
:-
325'$record_alias_info'(
_,
Alias)
:-
326 recorded(
'$thread_alias', [
_|Alias],
_),
recorded,
327 '$do_error'(permission_error(create,thread,alias(
Alias)), create_thread).
328'$record_alias_info'(
Id,
Alias)
:-
329 recorda(
'$thread_alias', [
Id|Alias],
_).
332thread_defaults(
Defaults)
:-
334 '$do_error'(uninstantiation_error(
Defaults), thread_defaults(
Defaults)).
335thread_defaults([stack(
Stack), trail(
Trail), system(
System), detached(
Detached), at_exit(
AtExit)])
:-
336 recorded(
'$thread_defaults',[
Stack,
Trail,
System,
Detached,
AtExit],
_).
338thread_default(
Default)
:-
340 recorded(
'$thread_defaults',
Defaults,
_),
341 '$thread_default'(
Default,
Defaults).
342thread_default(stack(
Stack))
:- thread_default,
343 recorded(
'$thread_defaults',[
Stack,
_,
_,
_,
_],
_).
344thread_default(trail(
Trail))
:- thread_default,
345 recorded(
'$thread_defaults',[
_,
Trail,
_,
_,
_],
_).
346thread_default(system(
System))
:- thread_default,
347 recorded(
'$thread_defaults',[
_,
_,
System,
_,
_],
_).
348thread_default(detached(
Detached))
:- thread_default,
349 recorded(
'$thread_defaults',[
_,
_,
_,
Detached,
_],
_).
350thread_default(at_exit(
AtExit))
:- thread_default,
351 recorded(
'$thread_defaults',[
_,
_,
_,
_,
AtExit],
_).
352thread_default(
Default)
:-
353 '$do_error'(type_error(thread_option,
Default),thread_default(
Default)).
355'$thread_default'(stack(
Stack), [
Stack,
_,
_,
_,
_]).
356'$thread_default'(trail(
Trail), [
_,
Trail,
_,
_,
_]).
357'$thread_default'(system(
System), [
_,
_,
System,
_,
_]).
358'$thread_default'(detached(
Detached), [
_,
_,
_,
Detached,
_]).
359'$thread_default'(at_exit(
AtExit), [
_,
_,
_,
_,
AtExit]).
361thread_set_defaults(
V)
:- var(
V),
var,
362 '$do_error'(instantiation_error, thread_set_defaults(
V)).
363thread_set_defaults([
Default| Defaults])
:- thread_set_defaults,
364 '$thread_set_defaults'([
Default| Defaults], thread_set_defaults([
Default| Defaults])).
365thread_set_defaults(
T)
:-
366 '$do_error'(type_error(list,
T), thread_set_defaults(
T)).
368'$thread_set_defaults'([],
_).
369'$thread_set_defaults'([
Default| Defaults],
G)
:- '$thread_set_defaults',
370 '$thread_set_default'(
Default,
G),
371 '$thread_set_defaults'(
Defaults,
G).
373thread_set_default(
V)
:- var(
V),
var,
374 '$do_error'(instantiation_error, thread_set_default(
V)).
375thread_set_default(
Default)
:-
376 '$thread_set_default'(
Default, thread_set_default(
Default)).
378'$thread_set_default'(stack(
Stack),
G)
:-
380 '$do_error'(type_error(integer,
Stack),
G).
381'$thread_set_default'(stack(
Stack),
G)
:-
382 Stack < 0,
'$thread_set_default',
383 '$do_error'(domain_error(not_less_than_zero,
Stack),
G).
384'$thread_set_default'(stack(
Stack),
_)
:- '$thread_set_default',
385 recorded(
'$thread_defaults', [
_,
Trail,
System,
Detached,
AtExit],
Ref),
387 recorda(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
AtExit],
_).
389'$thread_set_default'(trail(
Trail),
G)
:-
391 '$do_error'(type_error(integer,
Trail),
G).
392'$thread_set_default'(trail(
Trail),
G)
:-
393 Trail < 0,
'$thread_set_default',
394 '$do_error'(domain_error(not_less_than_zero,
Trail),
G).
395'$thread_set_default'(trail(
Trail),
_)
:- '$thread_set_default',
396 recorded(
'$thread_defaults', [
Stack,
_,
System,
Detached,
AtExit],
Ref),
398 recorda(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
AtExit],
_).
400'$thread_set_default'(system(
System),
G)
:-
402 '$do_error'(type_error(integer,
System),
G).
403'$thread_set_default'(system(
System),
G0)
:-
404 System < 0,
'$thread_set_default',
405 '$do_error'(domain_error(not_less_than_zero,
System),
G0).
406'$thread_set_default'(system(
System),
_)
:- '$thread_set_default',
407 recorded(
'$thread_defaults', [
Stack,
Trail,
_,
Detached,
AtExit],
Ref),
409 recorda(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
AtExit],
_).
411'$thread_set_default'(detached(
Detached),
G)
:-
412 Detached \== '$thread_set_default',
Detached \== '$thread_set_default',
'$thread_set_default',
413 '$do_error'(type_error(boolean,
Detached),
G).
414'$thread_set_default'(detached(
Detached),
_)
:- '$thread_set_default',
415 recorded(
'$thread_defaults', [
Stack,
Trail,
System,
_,
AtExit],
Ref),
417 recorda(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
AtExit],
_).
419'$thread_set_default'(at_exit(
AtExit),
G)
:-
421 '$do_error'(type_error(callable,
AtExit),
G).
422'$thread_set_default'(at_exit(
AtExit),
_)
:- '$thread_set_default',
423 recorded(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
_],
Ref),
425 '$current_module'(
M),
426 recorda(
'$thread_defaults', [
Stack,
Trail,
System,
Detached,
M:AtExit],
_).
428'$thread_set_default'(
Default,
G)
:-
429 '$do_error'(domain_error(thread_default,
Default),
G).
441 '$do_error'(domain_error(thread_or_alias,
Id), thread_self(
Id)).
444 '$thread_id_alias'(
Id0,
Id).
496 '$do_error'(uninstantiation_error(
Status),thread_join(
Id,
Status)).
498 '$check_thread_or_alias'(
Id, thread_join(
Id,
Status)),
499 '$thread_id_alias'(
Id0,
Id),
501 '$mk_tstatus_key'(
Id0,
Key),
504 '$thread_destroy'(
Id0).
507 (
Id == main
; Id == 0),
,
508 '$do_error'(permission_error(cancel, thread, main), thread_cancel(
Id)).
510 thread_signal(
Id, throw(error(thread_cancel(
Id),thread_cancel(
Id)))).
513 '$check_thread_or_alias'(
Id, thread_detach(
Id)),
514 '$thread_id_alias'(
Id0,
Id),
515 '$detach_thread'(
Id0),
516 '$mk_tstatus_key'(
Id0,
Key),
518 '$erase_thread_info'(
Id0),
519 '$thread_destroy'(
Id0)
521 '$thread_unlock'(
Id0)
537 '$do_error'(instantiation_error, thread_exit(
Term)).
539 throw(
'$thread_finished'(exited(
Term))).
541'$run_at_thread_exit'(
_Id0)
:-
542 '$thread_run_at_exit'(
G,
M),
543 catch(once(
M:G),
_, fail),
545'$run_at_thread_exit'(
Id0)
:-
547 catch(once(
Hook),
_,fail),
549'$run_at_thread_exit'(
_).
569 recordz(
'$thread_exit_hook',[
Id0|Goal],
_).
623 catch(thread_property(
Id, status(
Status)),
624 error(existence_error(
_,
_),
_), fail).
627'$thread_id_alias'(
Id,
Alias)
:-
628 recorded(
'$thread_alias', [
Id|Alias],
_),
recorded.
629'$thread_id_alias'(
Id,
Id).
633thread_property(
Prop)
:-
634 '$check_thread_property'(
Prop, thread_property(
Prop)),
636 '$thread_property'(
Prop,
Id).
673 '$check_thread_or_alias'(
Id, thread_property(
Id,
Prop))
674 ; '$enumerate_threads'(
Id)
676 '$check_thread_property'(
Prop, thread_property(
Id,
Prop)),
677 '$thread_id_alias'(
Id0,
Id),
678 '$thread_property'(
Prop,
Id0).
680'$enumerate_threads'(
Id)
:-
684 '$thread_stacks'(
Id,
_,
_,
_).
686'$thread_property'(alias(
Alias),
Id)
:-
687 recorded(
'$thread_alias', [
Id|Alias],
_).
688'$thread_property'(status(
Status),
Id)
:-
689 '$mk_tstatus_key'(
Id,
Key),
694'$thread_property'(detached(
Detached),
Id)
:-
695 (
'$thread_detached'(
Id,
Detached)
-> '$thread_detached'
; Detached = '$thread_detached' ).
696'$thread_property'(at_exit(
M:G),
_Id)
:-
697 '$thread_run_at_exit'(
G,
M).
698'$thread_property'(stack(
Stack),
Id)
:-
699 '$thread_stacks'(
Id,
Stack,
_,
_).
700'$thread_property'(trail(
Trail),
Id)
:-
701 '$thread_stacks'(
Id,
_,
Trail,
_).
702'$thread_property'(system(
System),
Id)
:-
703 '$thread_stacks'(
Id,
_,
_,
System).
706 format(user_error,
'------------------------------------------------------------------------~n',[]),
707 format(user_error,
'~t~a~48+~n',
'Thread Detached Status'),
708 format(user_error,
'------------------------------------------------------------------------~n',[]),
711 '$thread_id_alias'(
Id,
Alias),
712 format(user_error,
'~t~q~30+~33|~w~42|~q~n', [
Alias,
Detached,
Status]),
715 format(user_error,
'------------------------------------------------------------------------~n',[]).
718'$check_thread_or_alias'(
Term,
Goal)
:-
720 '$do_error'(instantiation_error,
Goal).
721'$check_thread_or_alias'(
Term,
Goal)
:-
723 '$do_error'(domain_error(thread_or_alias,
Term),
Goal).
724'$check_thread_or_alias'(
Term,
Goal)
:-
725 atom(
Term),
\+ recorded(
'$thread_alias',[
_|Term],
_),
recorded,
726 '$do_error'(existence_error(thread,
Term),
Goal).
727'$check_thread_or_alias'(
Term,
Goal)
:-
728 integer(
Term),
\+ '$valid_thread'(
Term),
'$valid_thread',
729 '$do_error'(existence_error(thread,
Term),
Goal).
730'$check_thread_or_alias'(
_,
_).
732'$check_thread_property'(
Term,
_)
:-
734'$check_thread_property'(alias(
_),
_)
:- '$check_thread_property'.
735'$check_thread_property'(detached(
_),
_)
:- '$check_thread_property'.
736'$check_thread_property'(at_exit(
_),
_)
:- '$check_thread_property'.
737'$check_thread_property'(status(
_),
_)
:- '$check_thread_property'.
738'$check_thread_property'(stack(
_),
_)
:- '$check_thread_property'.
739'$check_thread_property'(trail(
_),
_)
:- '$check_thread_property'.
740'$check_thread_property'(system(
_),
_)
:- '$check_thread_property'.
741'$check_thread_property'(
Term,
Goal)
:-
742 '$do_error'(domain_error(thread_property,
Term),
Goal).
744'$check_mutex_or_alias'(
Term,
Goal)
:-
746 '$do_error'(instantiation_error,
Goal).
747'$check_mutex_or_alias'(
Term,
Goal)
:-
749 '$do_error'(domain_error(mutex_or_alias,
Term),
Goal).
750'$check_mutex_or_alias'(
Term,
Goal)
:-
751 atom(
Term),
\+ recorded(
'$mutex_alias',[
_|Term],
_),
recorded,
752 '$do_error'(existence_error(mutex,
Term),
Goal).
753'$check_mutex_or_alias'(
Term,
Goal)
:-
756 '$do_error'(existence_error(mutex,
Term),
Goal).
757'$check_mutex_or_alias'(
_,
_).
759'$check_mutex_property'(
Term,
_)
:-
761'$check_mutex_property'(alias(
_),
_)
:- '$check_mutex_property'.
762'$check_mutex_property'(status(
Status),
Goal)
:- '$check_mutex_property',
767 ; Status = locked(
_,
_)
->
769 ; '$do_error'(domain_error(mutex_property, status(
Status)),
Goal)
771'$check_mutex_property'(
Term,
Goal)
:-
772 '$do_error'(domain_error(mutex_property,
Term),
Goal).
774'$mk_tstatus_key'(
Id0,
Key)
:-
775 atomic_concat(
'$thread_exit_status__',
Id0,
Key).
806 format(
"not implemented yet: ~w, ~w, ~w~n",[
Id,
Key,
Val]).
872mutex_create(
Id,
Options)
:-
874 '$do_error'(uninstantiation_error(
Id), mutex_create(
Id,
Options)).
875mutex_create(
Id,
Options)
:-
876 Goal = mutex_create(
Id,
Options),
877 '$mutex_options'(
Options,
Alias,
Goal),
883'$mutex_options'(
Var,
_,
Goal)
:-
885 '$do_error'(instantiation_error,
Goal).
886'$mutex_options'([],
_,
_)
:- '$mutex_options'.
887'$mutex_options'([
Option| Options],
Alias,
Goal)
:- '$mutex_options',
888 '$mutex_option'(
Option,
Alias,
Goal),
889 '$mutex_options'(
Options,
Alias,
Goal).
890'$mutex_options'(
Options,
_,
Goal)
:-
891 '$do_error'(type_error(list,
Options),
Goal).
893'$mutex_option'(
Var,
_,
Goal)
:-
895 '$do_error'(instantiation_error,
Goal).
896'$mutex_option'(alias(
Alias),
Alias,
Goal)
:- '$mutex_option',
899 ; '$do_error'(type_error(atom,
Alias),
Goal)
901'$mutex_option'(
Option,
_,
Goal)
:-
902 '$do_error'(domain_error(mutex_option,
Option),
Goal).
915 '$unlock_all_thread_mutexes'(
Tid).
917'$unlock_all_thread_mutexes'(
Tid)
:-
919 '$mutex_info'(
Id,
NRefs,
Tid),
921 '$mutex_unlock_all'(
Id),
923'$unlock_all_thread_mutexes'(
_).
925'$mutex_unlock_all'(
Id)
:-
926 '$mutex_info'(
Id,
NRefs,
_),
929 '$mutex_unlock_all'(
Id).
944 '$mutex_info'(
Id,
NRefs,
T).
946mutex_property(
Mutex,
Prop)
:-
948 '$check_mutex_or_alias'(
Mutex, mutex_property(
Mutex,
Prop))
949 ; recorded(
'$mutex_alias', [
_|Mutex],
_)
951 '$check_mutex_property'(
Prop, mutex_property(
Mutex,
Prop)),
952 '$mutex_id_alias'(
Id,
Mutex),
953 '$mutex_property'(
Id,
Prop).
955'$mutex_property'(
Id, alias(
Alias))
:-
956 recorded(
'$mutex_alias', [
Id|Alias],
_),
958'$mutex_property'(
Id, status(
Status))
:-
959 '$mutex_info'(
Id,
Count,
HoldingThread),
963 '$thread_id_alias'(
HoldingThread,
Alias),
964 once((
Thread = Alias; Thread = HoldingThread)),
965 Status = locked(
Thread,
Count)
986message_queue_create(
Id,
Options)
:-
988 '$do_error'(uninstantiation_error(
Id), message_queue_create(
Id,
Options)).
989message_queue_create(
Id,
Options)
:-
991 '$do_error'(instantiation_error, message_queue_create(
Id,
Options)).
992message_queue_create(
Id, [])
:- message_queue_create,
993 '$message_queue_create'(
Id).
994message_queue_create(
Id, [alias(
Alias)])
:-
996 '$do_error'(instantiation_error, message_queue_create(
Id, [alias(
Alias)])).
997message_queue_create(
Id, [alias(
Alias)])
:-
998 \+ atom(
Alias),
atom,
999 '$do_error'(type_error(atom,
Alias), message_queue_create(
Id, [alias(
Alias)])).
1000message_queue_create(
Id, [alias(
Alias)])
:- var(
Id),
var,
1001 (
recorded(
'$thread_alias', [
_|Alias],
_)
->
1002 '$do_error'(permission_error(create,queue,alias(
Alias)),message_queue_create(
Alias, [alias(
Alias)]))
1003 ; '$message_queue_create'(
Id),
1004 recordz(
'$thread_alias', [
Id|Alias],
_)
1006message_queue_create(
Alias, [alias(
Alias)])
:- message_queue_create,
1007 (
recorded(
'$thread_alias', [
_|Alias],
_)
->
1008 '$do_error'(permission_error(create,queue,alias(
Alias)),message_queue_create(
Alias, [alias(
Alias)]))
1009 ; '$message_queue_create'(
Alias)
1011message_queue_create(
Id, [
Option| _])
:-
1012 '$do_error'(domain_error(queue_option,
Option), message_queue_create(
Id, [
Option| _])).
1013message_queue_create(
Id,
Options)
:-
1014 '$do_error'(type_error(list,
Options), message_queue_create(
Id,
Options)).
1028 '$message_queue_create'(
Id)
1030 '$message_queue_create'(
Id)
1031 ; '$do_error'(uninstantiation_error(
Id), message_queue_create(
Id))
1046 '$do_error'(instantiation_error,message_queue_destroy(
Name)).
1048 recorded(
'$thread_alias', [
Id|Alias],
Ref),
1050 '$message_queue_destroy'(
Id),
1054 '$message_queue_destroy'(
Name),
1055 recorded(
'$thread_alias', [
Name|_Alias],
Ref),
1073message_queue_property(
Id, alias(
Alias) )
:-
1074 recorded(
'$thread_alias',[
Id|Alias],
_).
1075message_queue_property(
Alias, size(
Size) )
:-
1077 recorded(
'$thread_alias',[
Id|Alias],
_),
1078 '$message_queue_size'(
Id,
Size).
1079message_queue_property(
Id, size(
Size) )
:-
1080 '$message_queue_size'(
Id,
Size).
1114 '$do_error'(instantiation_error,thread_send_message(
Queue,
Term)).
1116 recorded(
'$thread_alias',[
Id|Queue],
_R),
recorded,
1117 '$message_queue_send'(
Id,
Term).
1119 '$message_queue_send'(
Queue,
Term).
1159 '$do_error'(instantiation_error,thread_get_message(
Queue,
Term)).
1161 recorded(
'$thread_alias',[
Id|Queue],
_R),
recorded,
1162 '$message_queue_receive'(
Id,
Term).
1164 '$message_queue_receive'(
Queue,
Term).
1226 '$do_error'(instantiation_error,thread_peek_message(
Queue,
Term)).
1228 recorded(
'$thread_alias',[
Id|Queue],
_R),
recorded,
1229 '$message_queue_peek'(
Id,
Term).
1230tthread_peek_message(
Queue,
Term)
:-
1231 '$message_queue_peek'(
Queue,
Term).
1265 '$do_error'(instantiation_error,thread_sleep(
Time)).
1269 '$thread_sleep'(
Time,
0,
_,
_)
1275 STime is integer(float_integer_part(
Time)),
1276 NTime is integer(float_fractional_part(
Time))
*1000000000,
1277 '$thread_sleep'(
STime,
NTime,
_,
_)
1281 '$do_error'(type_error(number,
Time),thread_sleep(
Time)).
1284thread_signal(
Id,
Goal)
:-
1285 '$check_thread_or_alias'(
Id, thread_signal(
Id,
Goal)),
1287 '$thread_id_alias'(
Id0,
Id),
1291 recorda(
'$thread_signal', [
Id0| Goal],
_),
1292 '$signal_thread'(
Id0).
1294'$thread_gfetch'(
G)
:-
1296 recorded(
'$thread_signal',[
Id|G],
R),
1355 '$current_module'(
M),
1356 '$thread_local'(
X,
M).
1358'$thread_local'(
X,
M)
:- var(
X),
var,
1359 '$do_error'(instantiation_error,
thread_local(
M:X)).
1360'$thread_local'(
Mod:Spec,
_)
:- '$thread_local',
1361 '$thread_local'(
Spec,
Mod).
1362'$thread_local'([],
_)
:- '$thread_local'.
1363'$thread_local'([
H|L],
M)
:- '$thread_local',
'$thread_local'(
H,
M),
'$thread_local'(
L,
M).
1364'$thread_local'((
A,
B),
M)
:- '$thread_local',
'$thread_local'(
A,
M),
'$thread_local'(
B,
M).
1365'$thread_local'(
X,
M)
:- '$thread_local',
1366 '$thread_local2'(
X,
M).
1368'$thread_local2'(
A/N,
Mod)
:- integer(
N),
atom(
A),
atom,
1370 (
Mod \= idb
-> '$predicate_flags'(
T,
Mod,
F,
F)
; '$predicate_flags'),
1371 (
'$install_thread_local'(
T,
Mod)
-> '$install_thread_local'
;
1372 F /\ 0'$install_thread_local'
=\= 0 -> '$do_error'(permission_error(modify,dynamic_procedure,
A/N),
thread_local(
Mod:A/N))
;
1373 '$do_error'(permission_error(modify,static_procedure,
A/N),
thread_local(
Mod:A/N))
1375'$thread_local2'(
X,
Mod)
:-
1376 '$do_error'(type_error(callable,
X),
thread_local(
Mod:X)).
1386
catch( : Goal,+ Exception,+ Action)
must_be_callable( ?_Goal_ )
thread_create(: Goal, - Id)
thread_create(: Goal, - Id, + Options)
thread_join(+ Id, - Status)
current_thread(+ Id, - Status)
thread_property(? Id, ? Property)
thread_statistics(+ Id, + Key, - Value)
message_queue_create(? Queue)
message_queue_destroy(+ Queue)
thread_get_message(? Term)
thread_get_message(+ Queue, ? Term)
thread_peek_message(? Term)
thread_peek_message(+ Queue, ? Term)
thread_send_message(+ Term)
thread_send_message(+ QueueOrThreadId, + Term)
current_mutex(? MutexId, ? ThreadId, ? Count)
between(+ Low:int, + High:int, ? Value:int)