
# Workers and SMP

> Run the kernel off the main thread, on one or several CPUs.

```js
const vm = await createKernel({
  worker: true,
  distro, // a path or URL
  net: { kind: "net", backend: { kind: "direct" } },
  disks: [{ kind: "file", path: "data.img" }],
});
```

The kernel runs in a worker thread or Web Worker, with the same API. Disks and the network are given as specs, which the worker builds: `{ kind: "file", path }` on Node, `{ kind: "http", url }` and `{ kind: "data", template: "bundled" }` in browsers. Input and frames go through shared memory when it is available (`vm.transport` says).

::warning
Worker mode is experimental.
::

## Several CPUs

An SMP kernel (a bundle with the SMP patch) boots on several CPUs with `cpus: 4`, each CPU in a thread of its own on one shared memory.

In browsers that needs a cross-origin isolated page and `worker: true`, because a CPU blocks while it waits for another, which a page's main thread may not. `webCpuBlocker()` says why it cannot, and `vm.stats().cpus` how many CPUs the kernel got.

On a server, `worker: true` keeps the event loop free at no cost in speed, and `cpus: 4` gets most of what more CPUs give (about 3x on parallel work; 8 or 16 add little, and each CPU adds to boot time and takes 9 MiB of guest memory). `node test/profile.ts` measures your host, and the page's `/profile.html` a browser.
