var sab = new SharedArrayBuffer(1024);
worker.postMessage(sab);
var int32 = new Int32Array(sab);
//worker 1
Atomics.add(int32, 0, 1);
//worker 2
Atomics.add(int32, 0, 1);
//worker 3
Atomics.add(int32, 0, 1);
Performance
Single Thread | Multi Thread |
---|---|
0 | 0 |
class Vec3 {
x: float32;
y: float32;
z: float32;
constructor(x: float32, y: float32, z: float32): Vec3 {
this.x = x;
this.y = y;
this.z = z;
return this;
}
add(b: Vec3): Vec3 {
return new Vec3(
this.x + b.x,
this.y + b.y,
this.z + b.z
);
}
}
export function newVec3(x: float32, y: float32, z: float32): Vec3 {
return new Vec3(x, y, z);
}
export function addVec3(a:Vec3, b:Vec3): Vec3 {
return a.add(b);
}
export function destroyVec3(a:Vec3): void {
delete a;
}
Links
Future WebHPC & Parallel Programming TurboScript playground