2
v8 :: Script :: Run에 대한 시간 초과를 설정하고 싶습니다. 불행히도 v8에 약간의 경험이 있습니다. StartPreemtion + Loker + TerminateException을 사용해야한다는 것을 이해했습니다. 따라서 v8 :: Script :: Run은 별도의 스레드에 있어야합니다. 실행 시간 계산 및 제어는 주 스레드에 있어야합니다. v8에서 다른 스레드를 어떻게 만들 수 있습니까? 어떻게하는지 이해하도록 도와주세요. 다음은 코드 예제입니다.하지만 스레드의 기능이 시작되지 않습니다.v8에서 다른 스레드를 만들려면 어떻게해야합니까?
v8::Local<v8::Value> V8ExecuteString(v8::Handle<v8::String> source, v8::Handle<v8::String> filename)
{
// Compiling script
// ...
// End compiling script
DWORD start_tick = ::GetTickCount();
v8::Locker::StartPreemption(1);
{
v8::Unlocker unlocker;
boost::thread* th = new boost::thread([&]() {
v8::Locker locker;
v8::HandleScope handle_scope;
// Running script
// v8::Script::Run()
// End running script
});
}
// Calculation and control of the execution time
v8::Locker locker;
v8::HandleScope handle_scope;
while (true)
{
// terminate thread after 10 seconds
if(((::GetTickCount() - start_tick)/1000) > 10)
// v8::v8::TerminateException()
}
v8::Locker::StopPreemption();
}
대단히 감사합니다. 정말 도움이되었습니다. ResourceConstraints의 작동 방식을 이해하고 있습니까? http://stackoverflow.com/questions/15583446/the-semantics-of-v8resourceconstraints. 메모리 스크립트를 제한해야합니다. 다른 가능성이 없다는 것을 이해했습니다. – user2376509