Skip to content

Conversation

@JesseCodeBones
Copy link

I created a simple demo for AS Shared memory with Nodejs, please kindly verify if it is suitable to show this demo.
If it is not suitable, please feel free to decline this PR.
Regards

@@ -0,0 +1,4 @@
export function test(): void {
let str = "hello world";
trace(str, str.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong usage of built-in trace. Plaese see docs

Comment on lines +10 to +15
trace: function (offset, length) {
var bytes = new Uint8Array(sharedMemory.buffer, offset, length*2);
globalOffset = offset;
var string = new TextDecoder('utf8').decode(bytes);
console.log(string);
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AS uses UTF16-LE. Instead of all of this better to use --bindgen esm which already included proper trace and other bindings. See docs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I will use a customer function instead of builtin trace

@MaxGraey
Copy link
Member

Thanks for efforts! But this example is very basic and doesn't show how to use multithreading with the shared memory from AssemblyScript side. In addition, it contains a lot of mistakes. In general, multithreading on AS isn't yet ready for, because the memory manager is not thread safe, and mutable shared globals should be stored in linear shared memory (at least for "atomic" globals). For now all globals stored as thread local global variables by default. So closing this for now

@MaxGraey MaxGraey closed this Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants