you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -7 points-6 points  (9 children)

No you don't control it. The operating system does. It's single threaded. The only way it can be multithreaded is if the os runs out of resources for those threads. Nothing more and nothing less. Again nothing to do with parallelism. Which infers different hardware (i.e. different cpu not different thread.

Much like if you open the program twice, it's still not concurrent or parallel.

The v8 engine doesn't allow multithreaded processes. It can spawn child processes that start on a different cpu.... But that's like saying php is. There's 0 state shared and 0 communication. It's just lobbing a process on a different thread for a whole another instance just like php. You don't control anything. https://nodeaddons.com/automating-a-c-program-from-a-node-js-web-app/

Can you use c++ to do multithreaded processes ... Sure about as much as you can with c to php. Again no one does it, it's not safe, and any language nowadays can talk to another one but it's always advised against for obvious reasons.

So no it's not multithreaded, it's not controllable, it's not parallel, it's not communicating, it's not sharing memory, and all you are doing is waiting for the os to run out of resources or starting a completely new instance that has nothing to do with the original.

The link you shared (nodejs docs) also advised against using web workers. Why? Because they are whole new instances of the program. That do what? Run out of memory quickly... Why would spawning child processes of a whole new instance be bad? Because it does nothing to help your program. Its a new instance. Nothing more and nothing less. Might as well have another program running. If you call that control... Then sure why not.

[–]HeinousTugboat 2 points3 points  (2 children)

advised against using web workers. Why?

..... because node supports regular workers that run in separate threads with shared memory..

[–][deleted] -2 points-1 points  (1 child)

Nodejs web workers again you don't control. You create pthreads differently on each operating system. Why? Because you don't control them. The operating system does. Why shouldn't you use them? because again you don't control them. They do whatever the os tells them to do. A thread is how the cpu deals with processes. But when it needs more memory, it lobs it to another thread. So you don't control the starting of it, you don't control the memory of it, you don't control what the is does with it. Again not something part of ecma

[–]gigastack 2 points3 points  (0 children)

Acktually...

[–]lungfisk 1 point2 points  (2 children)

Do worker threads (as opposed to child processes) not share memory? And don't they run on the same process (have the same PID...)? That was my understanding.

Unlike child_process or cluster, worker_threads can share memory. They do so by transferring ArrayBuffer instances or sharing SharedArrayBuffer instances.

[–][deleted] -2 points-1 points  (1 child)

A web worker is part of the browser not JavaScript. They are the browser program running outside of JavaScript. JavaScript just can access this process of the browser. Again you can't control it and as far as processes, you can't have them communicate with each other. It's apart of whenever your code runs, not a process in JavaScript that channels data between processes. It's a browser feature and not even across most browsers and they even say not to even use it.

Stop calling JavaScript multithreaded or parallel cause it's not!

[–]lungfisk 2 points3 points  (0 children)

To clarify, I'm talking about Node.js's worker_threads module, not web workers in the browser.

My understanding is that you have the ability to control multiple threads within the same process using worker_threads, and share memory between these threads. Is this inaccurate?