Download SICStus Prolog User`s Manual

Transcript
302
SICStus Prolog
f2(SPAPI_ARG SP_new_term_ref(), 42);
...
// Note: no comma
}
If MULTI_SP_AWARE is not defined, i.e. --multi-sp-aware is not specified to splfr, then
all these macros expand to nothing, except SPAPI_ARG_PROTO_DECL0 which will expand to
void.
You can use SP_foreign_stash() to get access to a location, initially set to NULL, where
the foreign resource can store a void*. Typically this would be a pointer to a C struct that
holds all information that need to be stored in global variables. This struct can be allocated
and initialized by the foreign resource initialization function. It should be deallocated by
the foreign resource deinit function. See Section 9.3.7 [Miscellaneous C API Functions],
page 238, for details.
Most foreign resources that come with SICStus fully support multiple SICStus run-times.
For a particularly simple example, see the code for library(random). For an example
which hides the passing of the extra argument by using the C pre-processor, see the files in
‘library/clpfd/’.
11.5 Multiple Run-Times and Threads
Perhaps the primary reason to use more than one SICStus run-time in a process is to have
each run-time running in a separate thread. To this end, a few mutual exclusion primitives
are available. See Section 9.3.6 [Operating System Services], page 236, for details on mutual
exclusion locks.
Note that the SICStus run-time is not thread safe in general. See Section 9.4.3 [Calling
Prolog Asynchronously], page 241, for ways to safely interact with a running SICStus from
arbitrary threads.