JS_SuspendRequest 编辑

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);
NameTypeDescription
cxJSContext *The context whose current request is to be suspended or resumed.
saveDepthjsrefcount(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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:114 次

字数:3727

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文