summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2021-10-27 17:54:20 +0100
committerRobin Watts <Robin.Watts@artifex.com>2021-11-05 14:32:19 +0000
commit91e29d42a601689f13e9202fc6b582d53901fbc2 (patch)
tree7a8526c18f050af408749cc587a49a0ca13b1474 /doc
parent6dd05a013f66a9322f92f62fd2d46be9bfa82097 (diff)
downloadghostpdl-91e29d42a601689f13e9202fc6b582d53901fbc2.tar.gz
Runtime safety of non threadsafe devices and rework globals.
Some devices within Ghostscript (currently the x11 devices, uniprint and opvp/oprp) use non const static variables, so cannot be run in multiple instances at a time. We now maintain a core "count" of how many non-threadsafe devices are being used at any time. This value can be atomically adjusted by calls to gs_lib_ctx_nts_adjust. Non threadsafe devices now call gx_init_non_threadsafe_device either as or as part of their initialise_device proc. This function attempts to increment the non-threadsafe count and fails to init if there is already a non-threadsafe device running. On success, the device finalize method is modified so that it will decrement the count at the end. The known non-threadsafe devices are updated to call this. In order to have somewhere safe to store this count, we introduce a gs_globals structure, shared between instances. Setting this up without race conditions requires some new gp_ functions that can make use of platform specific threading primitives. We have these implemented for both windows and pthread based platforms. On other platforms, we drop back to the old unsafe mechanism for counting instances. While we do this work, we take the opportunity to push the gs_memory_t pointer used for non-threadsafe debug printing into thread local storage. This enables us to remove the remaining GS_THREADSAFE guarded compilation from the source code. What is left is broadly down to allowing debugging collection for statistics, and these are now controlled by specific COLLECT_STATS_XXX defines. It is assumed that anyone wanting to collect such stats is smart enough to not try to do so while using Ghostscript in a multi-instance environment.
Diffstat (limited to 'doc')
-rw-r--r--doc/API.htm23
1 files changed, 11 insertions, 12 deletions
diff --git a/doc/API.htm b/doc/API.htm
index 1fcc41812..34ab2d651 100644
--- a/doc/API.htm
+++ b/doc/API.htm
@@ -378,20 +378,19 @@ Create a new instance of Ghostscript.
This instance is passed to most other gsapi functions.
The caller_handle is the default value that will be provided to callback functions.
-<b>Unless Ghostscript has been compiled with the </code>GS_THREADSAFE</code>
-define, only one instance at a time is supported.</b>
-
-<p>Historically, Ghostscript has only supported a single instance; any
-attempt to create more than one at a time would result in gsapi_new_instance
-returning an error. Experimental work has been done to lift this
-restriction; if Ghostscript is compiled with the GS_THREADSAFE define
-then multiple concurrent instances are permitted.</p>
+<b>On some platforms (those that do not support threading), only one
+instance of Ghostscript is supported at a time; any attempt to create
+more than one at a time would result in gsapi_new_instance
+returning an error.</p>
<p>While the core Ghostscript devices are believed to be thread safe
-now, certain devices are known not to be (particularly the contrib
-devices). The makefiles currently make no attempt to exclude these
-from builds. If you enable GS_THREADSAFE then you should check to ensure
-that you do not rely on such devices (check for global variable use).</p>
+now, a handful of devices are known not to be (at least the x11 devices,
+uniprint, and the open printing devices). A new mechanism has been
+implemented that allows devices to check for concurrent use and to
+refuse to start up. The devices shipped with Ghostscript known to use
+global variables have had these calls added to them. Any authors of
+non-standard Ghostscript devices that use global variables should
+consider adding the same calls to their own code.</p>
<p>
The first parameter, is a pointer to an opaque pointer (&quot;<code>void **</code>&quot;).
The opaque pointer (&quot;<code>void *</code>&quot;) must be initialised to <code>NULL</code> before