File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Flags: --expose-gc --experimental-worker
2
+ 'use strict' ;
3
+
4
+ const common = require ( '../common' ) ;
5
+ const assert = require ( 'assert' ) ;
6
+ const { Worker } = require ( 'worker_threads' ) ;
7
+
8
+ {
9
+ const sharedArrayBuffer = new SharedArrayBuffer ( 12 ) ;
10
+ const local = Buffer . from ( sharedArrayBuffer ) ;
11
+
12
+ const w = new Worker ( `
13
+ const { parentPort, workerData } = require('worker_threads');
14
+ const local = Buffer.from(workerData.sharedArrayBuffer);
15
+
16
+ parentPort.on('message', () => {
17
+ local.write('world!', 6);
18
+ parentPort.postMessage('written!');
19
+ });
20
+ ` , {
21
+ eval : true ,
22
+ workerData : { sharedArrayBuffer }
23
+ } ) ;
24
+ w . on ( 'message' , common . mustCall ( ( ) => {
25
+ assert . strictEqual ( local . toString ( ) , 'Hello world!' ) ;
26
+ global . gc ( ) ;
27
+ w . terminate ( ) ;
28
+ } ) ) ;
29
+ w . postMessage ( { } ) ;
30
+ // This would be a race condition if the memory regions were overlapping
31
+ local . write ( 'Hello ' ) ;
32
+ }
You can’t perform that action at this time.
0 commit comments