Created
July 31, 2021 13:15
-
-
Save billywhizz/73aa1c01b1e35cbb6fc6aa13b2cc479e to your computer and use it in GitHub Desktop.
POSIX shared memory example for just.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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