| ||||||
SummaryIndicates to the JS engine that an application thread is entering a critical section that calls the JS API freely but does not block. | ||||||
Syntaxvoid JS_BeginRequest(JSContext *cx); | ||||||
DescriptionWhen your multi-threaded application wants to execute JS API calls on a thread, it should useJS_BeginRequest and JS_EndRequest to bracket maximal non-blocking hunks of native code that call the JS API. This "request model" serves two purposes: to interlock with the global mark/sweep garbage collector, and to optimize object locking to be lock-free in most cases. In order to achieve these purposes, JS_BeginRequest first checks that garbage collection is not in process. If it is, JS_BeginRequest waits until garbage collection is complete before locking the JS engine runtime and incrementing its request counter. After incrementing the counter, JS_BeginRequest unlocks the runtime if it previously locked it.
It is therefore imperative that native code executing within an active request on
It is safe to nest calls to
| ||||||
NotesJS_BeginRequest is available only if you compile the JS engine with JS_THREADSAFE defined. In a default engine compilation, JS_THREADSAFE is undefined.
| ||||||
See Also
|