Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared Memory (SharedArrayBuffer) #42

Open
aleks63 opened this issue Jun 6, 2019 · 5 comments
Open

Shared Memory (SharedArrayBuffer) #42

aleks63 opened this issue Jun 6, 2019 · 5 comments
Labels
question Further information is requested

Comments

@aleks63
Copy link

aleks63 commented Jun 6, 2019

How to use one global object/array in every workers of pool?

@wilk
Copy link
Owner

wilk commented Jul 17, 2019

I don't understand your case: can you explain it better with an example, please?

@wilk wilk added the question Further information is requested label Jul 17, 2019
@codepushr
Copy link

I think he is asking how to use shared memory between worker processes. For example have a large global object that all the workers can manipulate.

@codepushr
Copy link

Instead of opening a new issue I'd like to ask a similar question here:

Am I right to assume that if I wanted to access a global variable (for example an express app instance), I would have to use context or pass it via data - which, however, both don't support functions and classes.
So basically there's currently no way to access more complex data structures from within worker threads?

@wilk
Copy link
Owner

wilk commented Oct 19, 2019

@codepushr thanks for the clarification!

@aleks63 Sorry for the late response.
The documentation of SAB says that (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer):

The structured clone algorithm accepts SharedArrayBuffers and TypedArrays mapped onto SharedArrayBuffers. In both cases, the SharedArrayBuffer object is transmitted to the receiver resulting in a new, private SharedArrayBuffer object in the receiving agent (just as for ArrayBuffer). However, the shared data block referenced by the two SharedArrayBuffer objects is the same data block, and a side effect to the block in one agent will eventually become visible in the other agent.

So, basically you can send a SAB inside the data option and treat it like a SAB as you would use in traditional worker threads, following the documentation.

@codepushr The only thing you cannot pass via context are classes: https://github.com/wilk/microjob/blob/master/GUIDE.md#job-context
So, yes, you can pass functions via context.

darky pushed a commit to darky/microjob that referenced this issue Oct 25, 2019
@darky
Copy link
Contributor

darky commented Oct 26, 2019

fix #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants