On Thu, Jul 9, 2015 at 12:18 AM, Tim Trefren <[email protected]> wrote:
> Hello,
>
> I'm working on an application that executes scripts from untrusted users.
> These scripts are expected to define a certain function that we will pull
> out and run many times.
>
> I have implemented a watchdog thread that ensures that no single function
> call takes too long (if it does, I assume there is an infinite loop in the
> function).
>
> Now I am trying to limit memory usage. I investigated various approaches
> with setrlimit and ResourceConstraints::ConfigureDefaults but those both
> leave the program in a bad state when it runs out of memory. Instead, I
> would like to occasionally use `GetHeapStatistics` to inspect the heap and
> error out if it has grown too large.
>
> My question is this: is it required to acquire a v8:Locker lock before using
> GetHeapStatistics? I am passing a pointer to my isolate to the watchdog
> script so that it can call v8:TerminateExecution if necessary, which is
> explicitly allowed in the documentation. The documentation for Locker says
> that a lock must be acquired to access handles or object pointers, but it's
> not clear if it is required for GetHeapStatistics.
>
> Thanks,
> Tim

Yes, you need to acquire the isolate before calling
v8::Isolate::GetHeapStatistics(), it iterates over mutable data.

As a rule of thumb, if the documentation doesn't explicitly mention
that a function is thread-safe, it's not.

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to