Questions tagged [worker-thread]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
29 votes
3 answers
18k views

Node.js worker threads shared object/store

So, I was reading some stuff regarding Node.js and I was amazed when I came across Worker Threads. Having threads in my opinion is a great plus especially if you combine it with shared memory access. ...
0x_Anakin's user avatar
  • 3,239
27 votes
1 answer
15k views

When is better using clustering or worker_threads?

I have been reading about multi-processing on NodeJS to get the best understanding and try to get a good performance in heavy environments with my code. Although I understand the basic purpose and ...
jaume's user avatar
  • 545
24 votes
1 answer
9k views

Push vs Pull Queues on Google App Engine

So far, no one (not even the GAE docs) has been able to give me a really clear description of what the difference is between a push queue and a pull queue. My understanding is that the Task Queue API ...
IAmYourFaja's user avatar
  • 56.3k
22 votes
3 answers
17k views

nodejs - DataCloneError: function () { [native code] } could not be cloned

I'm trying to spawn threads (using the new Nodejs module 'worker_threads') and pass to each of them a complex object which is the 'page' object of a Puppeteer browser.newPage() instance. I tried both ...
cub33's user avatar
  • 598
14 votes
1 answer
8k views

Android: multiple intentservices or one intentservice with multiple intents?

I'm a little confused about intentService. The docs say that if you send an intentService multiple tasks (intents) then it will execute them one after the other on one separate thread. My question is -...
Jon's user avatar
  • 7,991
10 votes
1 answer
4k views

How to pass class instances with function through worker_thread.Worker to use function?

To contextualize, I would like to use class instances functions through a Worker Thread from NodeJS "worker_thread" module. In one main.js file I declare a class and instanciate a new Worker ...
Helloïs's user avatar
  • 164
9 votes
6 answers
5k views

Proper way to have an endless worker thread?

I have an object that requires a lot of initialization (1-2 seconds on a beefy machine). Though once it is initialized it only takes about 20 miliseconds to do a typical "job" In order to prevent it ...
Neil N's user avatar
  • 25k
9 votes
2 answers
3k views

How do I create a direct communication channel between two worker threads in Node.js

Is there a way to create a direct communication channel using new MessageChannel between two worker threads? For Eg: There is a main thread P that I have created using the worker_thread API, which ...
tusharmath's user avatar
  • 10.8k
8 votes
2 answers
27k views

C#, Event Handlers and Threading

I'm writing a little chat app, and I have this event handler: void o_Typing(object sender, EventArgs e) { MessageBox.Show("Fired!"); this.Text = "Fired!"; } o_Typing is a method in a class ...
user avatar
8 votes
2 answers
7k views

How to Prevent a Node.js 12 worker Thread from terminating immediately?

I have a Node.js application running an Express server and a worker thread that does something at regular intervals. When the server is stopped, I need to clean up a connection to an external system ...
Patrick Hund's user avatar
  • 19.8k
7 votes
1 answer
4k views

node worker_threads console.log comes after postMessage

node v10.16.3 I was running an worker_threads example from node official doc. I made some changes as want to test share variables. Here is an example work-thread.js const { Worker, isMainThread,...
Zhao Xiaojing's user avatar
7 votes
1 answer
15k views

PostMessage from WorkerThread to Main Window in MFC

I have a MFC application, which has a worker thread, what I want to do is to post message from worker thread to the Main GUI thread to update some status messages on GUI. What I have done so far is ...
Muhammad Ummar's user avatar
7 votes
2 answers
5k views

Nodejs and Express, use res.send() from a worker thread

In Nodejs, using Express as a server, I offload a heavy computation onto a worker thread. From the main application, I call the worker thread like this: // file: main.js const { Worker } = require("...
Hendrik Jan's user avatar
  • 4,682
6 votes
1 answer
2k views

When a workerThread is created in nodejs, does it utilize the same core in which nodejs process is running?

Let's assume i have a nodejs serverProgram with one api and it does some manipulations on the video file, sent via the http request. const saveVideoFile=(req,res)=>{ processAndSaveVideoFile(); /...
divine's user avatar
  • 4,843
6 votes
2 answers
2k views

How worker threads works in Nodejs?

Nodejs can not have a built-in thread API like java and .net do. If threads are added, the nature of the language itself will change. It’s not possible to add threads as a new set of available ...
Sandeep Patel's user avatar
6 votes
1 answer
3k views

Is there a way to safely bind texture using OpenGL in a worker thread of Qt GUI application?

I am currently working on a GUI software project for visualizing 3D scenes using Qt. The GUI allows user to load batches of 3D data files such as .obj with some .mtl support and .stl as well as 2D ...
ksming's user avatar
  • 1,432
6 votes
0 answers
2k views

[Nodejs - worker-threads]: Is there an option for the main thread to wait till all worker threads are done?

Is there an option by which we can make the main thread wait until all worker threads are done? In the below code, mainThread.js simply creates workers. The worker takes long time to execute. In this ...
Kruthika C S's user avatar
5 votes
1 answer
3k views

Node.js multithreading: What are Worker threads and how does it work?

I always believed that JS was a single threaded language which makes it inefficient for CPU intensive tasks. I recently came across worker threads and how it solves this inefficiency problem by ...
Jpark9061's user avatar
  • 1,004
5 votes
1 answer
3k views

How to share context between worker threads

I would like to create a worker thread in a node.js app and pass the current context to the new thread, so I would be able to access my variables and functions within the new thread, Is there is a ...
dev3dev's user avatar
  • 138
5 votes
1 answer
8k views

ERR_WORKER_OUT_OF_MEMORY in nodejs worker threads

I receive the error Error [ERR_WORKER_OUT_OF_MEMORY]: worker terminated due to reaching memory limit, when I try to run nodejs worker threads in resource constrained windows environment. What is the ...
Muthukumar's user avatar
  • 9,189
5 votes
3 answers
3k views

Scala, check if Actor has exited

in Scala 2.8 when I start actors, I can communicate via message passing. This in turn means that I can send the ultimate Exit() message or whatever I decide fits my protocol. But how will I check if ...
Felix's user avatar
  • 8,435
5 votes
0 answers
843 views

Test worker thread with mocks

My Node application uses AWS SDK, and in order to mock it locally I am using Jest's manual mocks. Basically I am placing in __mocks__ folder barebone mock of AWS SDK that simulates methods I use - and ...
Yuriy Galanter's user avatar
5 votes
0 answers
4k views

worker.on('error') not working when unhandled rejection happens in the worker

worker.js async function main() { throw new Error('Bullocks!'); } setTimeout(async () => { await main(); }, 1000); main.js const { Worker } = require('worker_threads'); const worker = new ...
Bagas Wahyu Hidayah's user avatar
5 votes
1 answer
949 views

How to send message to multiple threads from another one?

I have a worker which creates MessageChannel and sends one of ports to main thread // worker1.js const { parentPort, MessageChannel } = require('worker_threads'); const { port1, port2 } = new ...
Artur Aralin's user avatar
4 votes
2 answers
6k views

node: bad option: --experimental-worker

I am trying to experiment with worker_threads in node.js. const { Worker, isMainThread, parentPort } = require('worker_threads'); if (isMainThread) { // This code is executed in the main thread ...
user3807454's user avatar
4 votes
1 answer
8k views

Worker threads with ts-node

I am planning to have worker threads for socket.io rooms. I create a worker thread on the first connection to a room which then sets up firebase listeners. Unfortunately. I have common imports in the ...
Blaine's user avatar
  • 617
4 votes
1 answer
4k views

Terminating a Worker thread from a Parent thread - MFC

I've just started with learning MFC and I'm writing one dialog based application for better understanding of Multi-Threading. The main dialog has a progress bar, a Start button and a Cancel button. ...
MajorBlackViking's user avatar
4 votes
2 answers
249 views

Which of these functions is the more effective one?

When using the thread, 'invoke' is being used to avoid 'Cross Thread'(1) but, sometimes 'timer object' is being used to avoid 'CrossThread' (2) like this(for example) public partial class Form1 : ...
KDJ's user avatar
  • 78
4 votes
3 answers
1k views

Shared worker working before packing app, but not working after (electron)

I have an electron app where I am trying to push some CPU intensive tasks to a worker thread. This works well when I start the app using npm start, but after packing the app (with electron-packager ...
cheesemas46's user avatar
4 votes
1 answer
1k views

How many Worker Threads can be created at most?

In my tablet app I use many Fragments (of one class) next to eachother in one activity, and in this Fragment class I have: public void onActivityCreated(Bundle savedInstanceState) { super....
pjv's user avatar
  • 10.7k
4 votes
1 answer
461 views

Why is all of my output appearing before each brute-force attempt when attempting to crack an ethereum keystore wallet file in node.js

I found a post describing how to recover an Ethereum wallet keystore by guessing a single password, however, it uses node synchronous code, and I'm trying to convert it into asynchronous code so that ...
loud_flash's user avatar
4 votes
0 answers
310 views

tsconfig paths in worker_threads

I'm spinning up some node workers and need each worker to pull code from a path expressed in tsconfig's paths compiler options. How do you configure worker to acknowledge paths from tsconfig? here's ...
Tom Schreck's user avatar
  • 5,247
4 votes
0 answers
857 views

"Module did not self-register" error when trying to load bcrypt in worker thread

Sample project with issues: https://github.com/Suvitruf/bcrypt-child-process-crash-proof const {Worker, isMainThread} = require('worker_threads'); if(isMainThread) console.log("I'm ok, because I'...
Suvitruf - Andrei Apanasik's user avatar
3 votes
2 answers
8k views

Is it possible to use Node worker threads to perform database inserts?

I recently read about Node's "worker_threads" module that allows parallel execution of Javascript code in multiple threads which is useful for CPU-intensive operations. (NOTE: these are not ...
Bruce Wang's user avatar
3 votes
5 answers
9k views

403 Forbidden with php in worker mode. Only to php files from browser

First off let me start by saying that yes I have searched for this in google and in stackoverflow specifically, I have found many answers and tried them all. At this point I believe my only resource ...
Purefan's user avatar
  • 1,496
3 votes
1 answer
908 views

Why Node.js spins 7 threads per process

When a Node.js process is spun up top command shows 7 threads attached to the process. What are all these threads doing? Also, as the load on the API increases, with the request handlers themselves ...
cubsnlinux's user avatar
3 votes
4 answers
1k views

Basic multi-threading questions in C#

I'm new to multithreading and I'm working on parallelizing an area in my application. I've read a number of posts on this site but I'm still confused as to the best way to approach my problem: [1] In ...
alhazen's user avatar
  • 1,915
3 votes
1 answer
16k views

Can't resolve 'worker_threads' in create-react-app

I'm trying to use "worker_threads" in my react-app for some cpu-intensive works. but react-app can't find "worker_threads" in node.js library. Here is my code: const {Worker} = require('...
HesamSe's user avatar
  • 315
3 votes
2 answers
944 views

Boost Thread Specific Storage Question (boost/thread/tss.hpp)

The boost threading library has an abstraction for thread specific (local) storage. I have skimmed over the source code and it seems that the TSS functionality can be used in an application with any ...
Hassan Syed's user avatar
  • 20.3k
3 votes
0 answers
550 views

how to work with response object in nodejs stream, exceljs and worker thread

I am using worker thread and stream at same time in node JS project. At initial I was not able to pass res object through main process to worker thread. I saw many stackoverflow question and solution ...
sabin maharjan's user avatar
3 votes
1 answer
831 views

In electron app, when I using worker_thread, an exception occurs after using Command+Q to exit the app

My code is very simple: const { Worker } = require('worker_threads'); let script = `console.log('working...');`; new Worker(script, { eval: true }); I can see working... output in the console, but ...
Victor's user avatar
  • 167
3 votes
1 answer
932 views

Passing my stream to a worker thread node.js

I have to implement this custom method of Multer storage in order to encrypt file before saving it. I have implemented my function encrypt, which will comunicate with a worker thread. import { ...
ste9206's user avatar
  • 1,842
2 votes
8 answers
3k views

How to prevent memory leaks while cancelling an operation in a worker thread?

Currently i am working on a desktop application which consists mathematical analysiss.I am using qt for GUI and project written in c++. When user starts an analysis, i open a worker thread and start a ...
Qubeuc's user avatar
  • 982
2 votes
5 answers
6k views

Is it possible to call the main thread from a worker thread in Java?

I have a method called action() that deploys three threads. Each deployed thread or worker thread falls into a while loop based on a single instance variable of type boolean being true, for example ...
user9349193413's user avatar
2 votes
5 answers
7k views

How can I tell if a thread is finished executing without polling ThreadState?

Is there an elegant way to know when a worker thread is done executing so I can access resources it produced? For example if the worker thread queried a list of SQL Servers using ...
Mark Carpenter's user avatar
2 votes
1 answer
1k views

Does a worker thread need to sleep?

A normal worker thread runs in a loop in which it checks for available tasks in a queue and consumes them. I've seem some examples where the thread waits a couple of milliseconds when there is no ...
danijar's user avatar
  • 33.4k
2 votes
3 answers
2k views

How to pass user-defined data to a worker thread using IOCP?

Hey... I created a small test server using I/O completion ports and winsock. I can successfully connect and associate a socket handle with the completion port. But I don´t know how to pass user-...
Juarrow's user avatar
  • 2,304
2 votes
1 answer
2k views

How to insert a new data in mongoDB using worker thread in nodejs

I want to insert data into the mongoDB using worker thread Right now I have a worker file, whole purpose of worker file is to save the data into the mongoDB and mainjs is sending the name of the agent ...
ayush verma's user avatar
2 votes
3 answers
255 views

Empty Worker Threads, What are they?

While debugging a .NET Framework 3.5, WinForms application I spotted some "Worker Thread"s without a name. I know when you open an application you've got a one worker thread by default. However in ...
dr. evil's user avatar
  • 27.1k
2 votes
2 answers
1k views

Execute long running operations on the service

I'm building an application which have a Service. I know that all application components run in the same UI process, at least you specify it in the manifest. So to avoid ANR's messages i have three ...
AXSM's user avatar
  • 1,162