Whereas JS code is executed in a single thread, C++ module code may execute 
in parallel (with itself and JS) if queued to the thread pool -- which is 
common if the code makes blocking calls. Using the thread pool for C++ is 
optional, but if so, your shared C++ objects would have to be protected 
with mutexes etc.

Note that coding to the V8 api to move data to/from C++ code is 
error-prone. I've tried to address this with a project called Lode, which 
creates an external thread pool for C/C++ logic, and links it to Node via 
JSON messages. https://github.com/networkimprov/lode


On Wednesday, August 6, 2014 6:05:29 AM UTC-7, korniak wrote:
>
> *Overview:*
>
> I have a NodeJS server with a few C++ modules in it, executing one overall 
> "job". Some objects (C++ objects, let's say "singletons") in these modules 
> are common and their states after initialization should be shared between 
> each module. The initialization of those objects has to be done once during 
> server startup.
>
> *Example:*
>
> A, B - separate C++ modules which should be executed as one job
>
> x, y, z - shared C++ objects (possibly a lot of them)
>
>    1. Server receives a (http) request and processes it in *A* using *x*, 
>    *y* and *z*.
>    2. The (http) response goes from *A* to the client.
>    3. Server receives another (http) request and processes it in *B* also 
>    using *x*, *y* and *z*.
>    4. The (http) response goes from *B* to the client.
>
> *Questions:*
>
> Can you tell me if there is some known best practice of initialization and 
> sharing of these objects between all C++ modules?
>
> What is the lifecycle of a particular C++ module in NodeJS? When are they 
> removed from the memory?
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/49f5c8c1-07f9-41d6-ae94-12cd12314cb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to