Re: get unused integer



On 2008-05-19, Peter Van Weert <Peter.VanWeert@xxxxxxxxxxxxxx> wrote:
This is a multi-part message in MIME format.
--------------080602070604030909000003
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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).

Yip. Also a non-deterministic label/1 is most likely not what you
want. Finally, you'll start trying labels from 0 each time, so this
will get pretty slow eventually. Typically I'd use something like
this:

:- dynamic
last_label/1,
assigned/2.

get_new_label(Label, Procedure) :-
with_mutex(label, assign_label(Label, Procedure)).

assign_label(Label, Procedure) :-
retract(last_label(Num)), !,
Label is Num+1,
assert(last_label(Label)),
assert(assigned(Label, Procedure)).
assign_label(Label, Procedure) :-
assert(last_label(1)),
assert(assigned(1, Procedure)).

--- Jan
.



Relevant Pages

  • Re: get unused integer
    ... Simon Strobl schreef: ... it probably makes sense to adjust the ... label-assigning technique to this fact. ... cannot be threadsafe. ...
    (comp.lang.prolog)
  • Re: Forcing printing of a record multiple times
    ... If the qty value is available, VB code can find it and ... adjust the number of times that record is printed. ... Knowledge Base article that shows how to print multiple labels or skip used ...
    (microsoft.public.access.reports)
  • Re: Reports for Printers
    ... I have found that a report designed ... >>>>You should not have to install every printer in order ... >>> create labels. ... adjust the reports and labels and then load ...
    (microsoft.public.access.reports)
  • Printing partial forms
    ... Or, to word it differently, I don't want null fields, and their labels to ... I also need the form to adjust the placement of the fields, ... are no large blanks spaces where the unprinted, ...
    (microsoft.public.word.docmanagement)
  • RE: how to create mailing labels from excel data?
    ... column widths to the size of your labels; ... Col. C is the second column of labels, Column D is a narrow spacer, etc. Use ... as many columns as needed to match your blank sheet of labels. ... You will need to adjust the spacer ...
    (microsoft.public.excel.misc)