14

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?

2

2 Answers 2

24

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.

Sign up to request clarification or add additional context in comments.

4 Comments

can you translate to plain English please?
umm, can you explain why this means V8 does or doesn't have a GIL. I am pretty certain it doesn't but you need to make that more clear for readers. Having a single thread means it doesn't have a need for a GIL, from what I understand.
@AlexMills Having a single thread precisely means that you don't need a GIL because GIL is a synchronization mechanism used to ensure consistency of interpreter's internals when several threads are running inside the same interpreter. V8 doesn't have a GIL in the same sense as e.g. Python does, where interpreter itself has a lock which it takes and releases essentially across each N instructions. However absence of GIL does not mean you can run several threads inside the same instance of V8 - you have to perform locking externally to guarantee exclusive access to an instance.
@Vyacheslav Egorov So your JS app runs as multiple instance in multiple Isolate. Am I right?
4

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.