在v8源码 default-platform.h 中,DefaultPlatform类中有一个私有对象 worker_threads_task_runner_ ,是一个线程池对象,这里研究一下如何使用这个对象执行多个任务。
首先,参照hello-world.cc示例中的代码,因为isolate的需要和脚本执行在同一线程中,所以从isolate创建部分开始直至脚本执行完毕全部封装为一个函数。
内容不复杂,直接上源码吧。
main.cpp
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
#include "task.h"
#include "waitgroup.h"
void ExecJsScript( WaitGroup* wg