我们可以在 p5.js 中使用多处理或多线程吗?
Can we use MultiProcessing or MultiThreading in p5.js?
我目前正在从事一个需要我执行并行流程的项目,但我在 p5.js 中找不到任何方法来做到这一点。有人可以帮我吗。
p5 本身似乎与您加载它的网页紧密相关,并且浏览器环境使得只有一个 JavaScript 线程可以直接与该页面交互。但是,如果你有很多 non-drawing 数字运算要做,你可以使用 web worker(spec | MDN). A web worker is a separate thread, isolated from the thread interacting with the web page, that can run in parallel with it and communicate with it via postMessage
and (in some environments) shared memory. (See this note 更改共享内存来处理 Spectre 和崩溃;我也在我的新书 JavaScript:新玩具 的第 16 章中对此进行了详细介绍。如果您有兴趣,可以在我的个人资料中找到链接。)
我目前正在从事一个需要我执行并行流程的项目,但我在 p5.js 中找不到任何方法来做到这一点。有人可以帮我吗。
p5 本身似乎与您加载它的网页紧密相关,并且浏览器环境使得只有一个 JavaScript 线程可以直接与该页面交互。但是,如果你有很多 non-drawing 数字运算要做,你可以使用 web worker(spec | MDN). A web worker is a separate thread, isolated from the thread interacting with the web page, that can run in parallel with it and communicate with it via postMessage
and (in some environments) shared memory. (See this note 更改共享内存来处理 Spectre 和崩溃;我也在我的新书 JavaScript:新玩具 的第 16 章中对此进行了详细介绍。如果您有兴趣,可以在我的个人资料中找到链接。)