Example 3.5 shows that, when the Varstring
functions are used, if a single calling thread opens a query to an XSB
thread
,
will be protected from queries and commands posed
by other C threads until the query is closed, failed out of, or exits
via an error. In fact, queries (and commands) are protected when the
Varstring or fixed string interfaces are used. However,
consider what may happen when the register level interface is used.
In this case, a calling thread may call one or more API functions to
set up the registers, execute a command or query, call several more
API functions to obtain the output, and so on. For this reason, if an
application uses API commands that depend on user manipulation of
registers (xsb_command(),xsb_query(), xsb_query_string(), and xsb_next()) the user must ensure
that only one calling thread interacts with an XSB thread when that
thread in the course of executing a command or query. See $XSB_DIR/examples/c_calling_xsb/cregs_thread2.c for an example
of how mutexes can be used to protect XSB threads.