Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Created July 31, 2021 13:15
Show Gist options
  • Save billywhizz/73aa1c01b1e35cbb6fc6aa13b2cc479e to your computer and use it in GitHub Desktop.
Save billywhizz/73aa1c01b1e35cbb6fc6aa13b2cc479e to your computer and use it in GitHub Desktop.
POSIX shared memory example for just.js
const fd = just.sys.shmopen('/omgthisiscool')
const size = 1 * 1024 * 1024 * 1024
const ab = just.sys.mmap(fd, size)
const u32 = new Uint32Array(ab)
just.setInterval(() => {
just.print(Atomics.load(u32, 0))
}, 1000)
const fd = just.sys.shmopen('/omgthisiscool')
const size = 1 * 1024 * 1024 * 1024
just.fs.ftruncate(fd, size)
const ab = just.sys.mmap(fd, size)
const u32 = new Uint32Array(ab)
Atomics.store(u32, 0, 0)
just.setInterval(() => {
Atomics.add(u32, 0, 1)
}, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment