diff --git a/threads/README.md b/threads/README.md index 035f5d9..b171e21 100644 --- a/threads/README.md +++ b/threads/README.md @@ -26,3 +26,18 @@ $ git submodule update --init $ cd examples && npm install && npm run dev ``` And visit http://localhost + +# Architecture +In the thread that maintains the file system for `@bjorn3/browser_wasi_shim`, file access is awaited asynchronously, while in the thread executing the WASM, file access is performed synchronously. + +Since the functions called within the WASM are invoked synchronously, it is not possible to properly create web workers. Therefore, it is necessary to first create a dedicated thread for generating web workers. + +Please refer to the diagram below for more details. + + +![slide1](./architecture/slide1.svg) + +Additionally, since data of unknown size is being exchanged, an allocator is essential. A simple allocator is implemented on the assumption that the allocated memory will be released promptly. + + +![slide2](./architecture/slide2.svg) diff --git a/threads/architecture/architecture.pptx b/threads/architecture/architecture.pptx new file mode 100644 index 0000000..a9eaf3b Binary files /dev/null and b/threads/architecture/architecture.pptx differ diff --git a/threads/architecture/slide1.SVG b/threads/architecture/slide1.SVG new file mode 100644 index 0000000..ba4419d --- /dev/null +++ b/threads/architecture/slide1.SVG @@ -0,0 +1 @@ +File systemthread BWASIFarmAnimalWasmthread AThreadSpawnerthread DetcWASIFarmTo create threadMain threadWASIFarmthread EetcWASIFarmAnimalThread IDsimple allocatorAccess fileSharedArrayBufferWasmThe management offile descriptorsbetween threads isomitted.WASIFarmParkcommunicationPrecompiled WASMCreate threadAccess fileAccess fileAccess file \ No newline at end of file diff --git a/threads/architecture/slide2.SVG b/threads/architecture/slide2.SVG new file mode 100644 index 0000000..d7526c0 --- /dev/null +++ b/threads/architecture/slide2.SVG @@ -0,0 +1 @@ +Simple allocatormallocfreeIncrement the allocation count.Return the previously allocated memory location.allocatedMemoryLocation+= size;Decrement the allocation countallocationCount--;If the allocation count is 0,reset pointerif (allocationCount=== 0) {allocatedMemoryLocation= 0;}The lock is in place to prevent deadlocks. \ No newline at end of file