Re: get unused integer



Simon Strobl schreef:
As my program will use multiple threads anyway (although only at a
later stage of development), it probably makes sense to adjust the
label-assigning technique to this fact.

I think I can assign an identity to each parsing procedure (s(T1, T3,
Procedure) ...) and use the following simple code:

:- dynamic(assigned/2).

get_new_label(Label, Procedure) :-
label(Label),
not(assigned(Label, Procedure)),
assert(assigned(Label, Procedure)).
....
I never used multiple threads in (Swi) Prolog before.

So, maybe someone with greater experience would like to comment on
this code? Is it safe? Is it efficient?

I never wrote multithreaded Prolog code either, but even then it is obvious to me that

not(assigned(Label, Procedure)),
assert(assigned(Label, Procedure))

cannot be threadsafe. You'll need some form of synchronisation here. Section 8.4 of the SWI manual seems a good place to start (http://gollem.science.uva.nl/SWI-Prolog/Manual/threadsync.html).

Cheers,
Peter


begin:vcard
fn:Peter Van Weert
n:Van Weert;Peter
org:K.U.Leuven;Computer Science
adr:room 01.08;;Celestijnenlaan 200A;Heverlee;;3001;Belgium
email;internet:Peter.VanWeert@xxxxxxxxxxxxxx
title:DTAI (Declarative Languages and Artificial Intelligence)
x-mozilla-html:TRUE
url:http://www.cs.kuleuven.be/~petervw/
version:2.1
end:vcard