Obsolete since JSAPI 18
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Removed from SpiderMonkey at or prior to version 45.  Since then, a JSRuntime is tied to the thread that created it; it may not be accessed by any other thread.

Suspends the calling thread's current request, if any, to allow the thread to block or perform time-consuming calculations.

Syntax

jsrefcount JS_SuspendRequest(JSContext *cx);

void JS_ResumeRequest(JSContext *cx, jsrefcount saveDepth);
Name Type Description
cx JSContext * The context whose current request is to be suspended or resumed.
saveDepth jsrefcount (only in JS_ResumeRequest) The valued returned by the matching JS_SuspendRequest call.

Description

In JS_THREADSAFE builds, when a multi-threaded application is in a request but needs to block or perform lengthy computation that can race safely with the garbage collector, it should call JS_SuspendRequest before the time-consuming operation and JS_ResumeRequest after. For more information about thread safety and requests, see JS_THREADSAFE.

JS_SuspendRequest suspends any currently active requests associated with the context cx. This allows the runtime to perform garbage collection if needed and allows other threads to access objects that the calling thread had locked. The return value is the number of nested requests that were suspended. It may be 0.

JS_ResumeRequest resumes the previously suspended requests. The saveDepth argument must be the value returned by the matching JS_SuspendRequest call. If saveDepth is nonzero and garbage collection is underway, JS_ResumeRequest blocks until the garbage collector is done.

JSAPI 1.7 and earlier JS_SuspendRequest and JS_ResumeRequest are available only in JS_THREADSAFE builds. In SpiderMonkey 1.8 and later, these functions will be present, but will do nothing, in non-JS_THREADSAFE builds.

MXR ID Search for JS_SuspendRequest
MXR ID Search for JS_ResumeRequest