multithreading

Temporary disabling child processes from parent terminal at runtime

徘徊边缘 提交于 2021-01-28 22:13:16
问题 Brief: there is huge Linux application with many child processes, and I need something like that: /* parent process, far from fork*/ suppress_child_output_to_parent_tty(); printf("important message"); /* huge piece of code */ printf("important message"); restore_child_output_to_parent_tty(); I know that exist a standard way to do this by make pipe, fork, redirect STDOUT to that pipe, select&read pipe /write to parent stdout at the some loop at different thread, manually pause this loop when

Run different task in same asynchronous thread in C# [duplicate]

痴心易碎 提交于 2021-01-28 22:03:41
问题 This question already has an answer here : How do I create a scheduler which never executes more than one Task at a time using async-await? (1 answer) Closed 14 days ago . I had to ask since I cannot found the same way as UI BeginInvoke asynchronous done. My sample program running on Winforms and all the delegate method is calling in the main UI thread. I have log the status and found it run on same thread on different BeginInvoke . Log from Winforms UI: 13/01/2021 11:57:23

Node.js single-thread mechanism

雨燕双飞 提交于 2021-01-28 21:32:42
问题 I learnt Node.js is single-threaded and non-blocking. Here I saw a nice explanation How, in general, does Node.js handle 10,000 concurrent requests? But the first answer says The seemingly mysterious thing is how both the approaches above manage to run workload in "parallel"? The answer is that the database is threaded. So our single-threaded app is actually leveraging the multi-threaded behaviour of another process: the database. (1) which gets me confused. Take a simple express application

Calling an unsafe library object of from a different thread

别来无恙 提交于 2021-01-28 21:22:17
问题 I am using tikv/raft-rs library for implementing a consensus system. This library has a RawNode object which is a thread-unsafe object. We must execute some functions on this object periodically (example), hence I use a new thread for executing. Here are the constraints: I need to have this object on the main-thread doesn't have this object for accessing some its internal states. (e.g.: raw_node.is_leader ) This object must be accessed on a worker thread. Because of these constraints, this

Thread that calls function in a HTTP request throws RuntimeError: Working outside of application context

会有一股神秘感。 提交于 2021-01-28 21:15:46
问题 I have route within my Flask application that process a POST request and then sends an email to the client using the Flask-Mail library. I have the route returning a response to the client from checking the database before sending out an email. The email is sent from an individual thread, but I am getting this error thrown when trying to send out the email: RuntimeError: Working outside of application context. . I know that it is being thrown because the request was destroyed before the

Guidelines while using: ThreadPool.SetMaxThreads and ThreadPool.SetMinThreads in C#

此生再无相见时 提交于 2021-01-28 21:07:37
问题 In one of my applications, I have to use multiple threads. As a better approach, I have replaced a thread queue by ThreadPool . At start of Form, I set Min/Max Threads as follows: ThreadPool.SetMaxThreads(20,20) ThreadPool.SetMinThreads(1,1) Later on while using, I use ThreadPool as follow: Function() { ThreadPool.QueueUserWorkItem(new WaitCallback(Action), arguments); } I am not using any sort of DeQueue . It will be help full if some one can share their experience with ThreadPool (specially

Thread that calls function in a HTTP request throws RuntimeError: Working outside of application context

时光总嘲笑我的痴心妄想 提交于 2021-01-28 20:31:35
问题 I have route within my Flask application that process a POST request and then sends an email to the client using the Flask-Mail library. I have the route returning a response to the client from checking the database before sending out an email. The email is sent from an individual thread, but I am getting this error thrown when trying to send out the email: RuntimeError: Working outside of application context. . I know that it is being thrown because the request was destroyed before the

Multiple goroutines access/modify a list/map

前提是你 提交于 2021-01-28 20:10:52
问题 I am trying to implement a multithreaded crawler using a go lang as a sample task to learn the language. It supposed to scan pages, follow links and save them do DB. To avoid duplicates I'm trying to use map where I save all the URLs I've already saved. The synchronous version works fine, but I have troubles when I'm trying to use goroutines. I'm trying to use mutex as a sync object for map, and channel as a way to coordinate goroutines. But obviously I don't have clear understanding of them.

Monte Carlo simulation runs significantly slower than sequential

左心房为你撑大大i 提交于 2021-01-28 19:42:07
问题 I'm new to the concept of concurrent and parallel programing in general. I'm trying to calculate Pi using Monte Carlo method in C. Here is my source code: #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int main(void) { long points; long m = 0; double coordinates[2]; double distance; printf("Enter the number of points: "); scanf("%ld", &points); srand((unsigned long) time(NULL)); for(long i = 0; i < points; i++) { coordinates[0] = ((double) rand() / (RAND_MAX));

executorService.shutdownNow() doesn't stop the thread

廉价感情. 提交于 2021-01-28 19:41:02
问题 I have a scheduled Executor service setup like class Test { private final ScheduledExecutorService executor; public Test() { executor = Executors.newSingleThreadScheduledExecutor((runnable) -> { Thread thread = new Thread(runnable, this.getClass().getName()); thread.setDaemon(true); return thread; }); executor.scheduleWithFixedDelay( new TestRefreshTask(), 0, 50000, TimeUnit.MILLISECONDS ); } private class TestRefreshTask implements Runnable { @Override public void run() { //refresh some data