Skip to content

Commit a85e52c

Browse files
committed
Add shared memory example
1 parent 595fb35 commit a85e52c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

config/docker.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"App": {
33
"cluster": {
4-
"enabled": true
4+
"enabled": false
55
},
66
"database": {
77
"url": "mongodb://mongodb"

src/routes/threads.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const express = require('express');
22
const fb = require('fibonacci');
33
const runFibonacci = require('../workers/fibonacciWorker');
44
const runFibonacciPool = require('../workers/fibonacciWorkerPool');
5+
const runFibonacciShared = require('../workers/fibonacciWorkerShared');
56
const log = require('../log');
67

78
const router = express.Router();
@@ -21,4 +22,15 @@ router.get('/fibonacciThreadedPool', async (req, res) => {
2122
res.send('processing');
2223
});
2324

25+
router.get('/fibonacciThreadedShared', async (req, res) => {
26+
/**
27+
* Uses shared SharedArrayBuffer to share data with the workers
28+
*/
29+
const sharedUint8Array = new Uint8Array(new SharedArrayBuffer(4));
30+
for(let i= 0; i< 4; i++) {
31+
runFibonacciShared({ iterations: 1000, position: i, arr: sharedUint8Array }).then(result => console.log(result));
32+
}
33+
res.send('processing');
34+
});
35+
2436
module.exports = router;

0 commit comments

Comments
 (0)