Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the V8 javascript engine have a GIL?

Tags:

javascript

v8

I read that the V8 Javascript engine is a just in time compiler. And that PyPy is a Python interpreter that is also a just in time compiler. PyPy is known for having a GIL in the presence of multiple threads.

Does the V8 Javascript engine have something equivalent to a global interpreter lock (GIL) to deal with web worker threads?

And do all dynamic languages have problems dealing with multi-core and if so why do the JIT compilers have problems with a GIL?

like image 983
user782220 Avatar asked Jan 19 '13 00:01

user782220


Video Answer


2 Answers

Chromium Web Workers are implemented on top of V8 Isolates. Each Isolate is essentially a completely independent instance of V8 VM. Many Isolates can coexist in the same process and execute JavaScript code concurrently.

However each Isolate can only be owned by a single thread at any given moment of time. There is an Isolate level locking mechanism that embedder must use to ensure exclusive access to an Isolate.

like image 105
Vyacheslav Egorov Avatar answered Sep 18 '22 15:09

Vyacheslav Egorov


To answer your last question, I don't think GILs are something that must necessarily be present in dynamically interpreted or JIT compiled languages. For instance, PyPy has done some preliminary work on eliminating the GIL using software transactional memory. The fact that PyPy and CPython have GILs has more to do with the design decisions that were made earlier in their histories and the fact that their internal data structures are not thread-safe.

like image 28
David Sanders Avatar answered Sep 18 '22 15:09

David Sanders