using compiled javascript code from a different thread

87 views
Skip to first unread message

Guillermo González Fernández

unread,
Nov 13, 2012, 2:54:57 AM11/13/12
to v8-u...@googlegroups.com
Hi there! I am trying to embed v8's engine in an own application and I am finding problems related to threads. Is it possible to compile and run javascript code in a thread (main thread) and then access that implementation from a different thread?

I mean, I have a kind of plugin or shared object with a bunch of interfaces that I want to implement from Javascript side. This module is initialized from main thread, where javascript code is compiled and run, later on, this code is called from a different thread owned by other module, and then our 'segmentation fault' friend appears. Do I have to compile the javascript code everytime I get a call from a different thread?

Thanks in advance!!

Daniel C

unread,
Nov 13, 2012, 4:42:54 AM11/13/12
to v8-u...@googlegroups.com
hi guilleguillo:
  
Have a look at v8.h start from line number 3830. Maybe solve your problem.

Daniel Chen



jok...@gmail.com

unread,
Nov 13, 2012, 9:11:22 AM11/13/12
to v8-u...@googlegroups.com, jok...@gmail.com
Thank you. Adm!

-- pesan asli --
Subjek: [v8-users] using compiled javascript code from a different thread
Dari: Guillermo González Fernández <guille...@gmail.com>
Tanggal: 13-11-2012 14.54

Guillermo González Fernández

unread,
Nov 15, 2012, 2:42:56 AM11/15/12
to v8-u...@googlegroups.com
Thank you Daniel,

I don't know exactly what I was doing wrong, because I was using Lockers (right now, I think I don't need 'Isolates' stuff) and my application crashed. Maybe, I had missed some 'v8::Locker locker' in a critical section. The thing is, now I can compile the javascript code in the main thread and call it from different threads (simply using Lockers).

However, I realized I need to compile the js code in a different thread because a long compilation or run can block the main process, but I am finding problems (doing the same way) to compile and run js code or even use v8 sintaxis in a thread that is not the main. When I know more accurately the source of the problem or the solution I'll write it here!

Yang Guo

unread,
Nov 26, 2012, 4:45:26 AM11/26/12
to v8-u...@googlegroups.com
Javascript is inherently single-threaded. Multithreading in V8 are implemented as isolates, and as the name implies, threads are completely isolated from each other, including the execution stack, heap, and the compiled code. There is no way to use compiled code from one isolate in another one.

Yang
Reply all
Reply to author
Forward
0 new messages