Questions tagged [multithreading]

Multi-threading related questions including technique, structure, and safety issues.

Filter by
Sorted by
Tagged with
3
votes
2answers
64 views

Would it be possible to abstract multi-threading ability for programs not originaly designed for such?

Would it be feasible to provide (or further) multi-core threading ability for programs that weren't originally designed for such? And doing so by creating a "virtual" CPU core (or for i7's with ...
0
votes
2answers
126 views

How to avoid deadlock

I have queue of MoveableItems in a class BackgroundTaskQueue (based on example from Microsoft here). Clients call BackgroundTaskQueue.QueueBackgroundWorkItem to add a MoveableItem to the queue. An ...
0
votes
0answers
17 views

What is the difference between pthread scope vs. policy?

I'm reading OS Concepts for my undergrad OS class and came across this topic: Pthread scheduling (System and Process) Then I kept reading and came across POSIX Real-Time Scheduling that has two ...
-1
votes
2answers
113 views

Developing a C++ program on linux using two threads, always keeping one thread running

The title describes an idea of a solution to a more general problem. Here is the general problem: I am developing a program which looks roughly as follows: [read a lot of data, store in data ...
-1
votes
2answers
95 views

where to put Read/Write threads in c++ classes

I am programming a UART interface (in LINUX) and I want to use a class for that. The way I have it right now is I have a method for write and one for read. The reading is started in a new thread to ...
4
votes
0answers
183 views

Is it good approach to await async tasks in object destructor?

I'm currently working on class with some async tasks under the hood. In fact I need to delegate few tasks to asynchronous execution and be sure that all of them are finished before class was destroyed,...
1
vote
1answer
98 views

Parallel execution: 1 thread pool or N thread pools?

I have a tree generated by configuration. Each leaf of the tree is a long running task (like DB query, reading from file, etc.) that gives a result I want to store in a mirrored tree with only the ...
0
votes
3answers
160 views

How do you optimally and securely isolate processes when building an operating system from scratch?

I am trying to build software in JavaScript that emulates an operating system. For all intents and purposes, it is an operating system, even though it is JavaScript and we are running in the Node.js ...
-1
votes
3answers
258 views

Multiprocessing vs multithreading

During my last job interview which was about half year ago, the technical guy asked me, whether the better option is to use e.g. 100 processes to do some work, or only one process but with 100 threads....
6
votes
5answers
555 views

Implementing a hash table with true concurrency

This was recently a question I was asked in a screening and it got me thinking. I never totally settled on how the conversation ended, and I did some digging. None of the answers I saw seemed ...
0
votes
1answer
60 views

Launch threads continuously with predefined interval between threads

I'm currently using a third-party API to fetch results, using a REST client (Retrofit). The problem is that the amount of requests per second that I can do to the API is limited with interval: I can'...
-2
votes
1answer
68 views

Does accessing RAM from 2 threads double access time (synchronous access)?

As in topic. If i want to access RAM from 2 different threads, completly different cells in memory, do they queue and are sent asynchronously or queue? Lets say accessing memory from one thread (...
1
vote
1answer
38 views

Design tips for waiting for a user input while working on another thread

I am working on an application with multiple threads (using Qt, C++). One of this threads is designed to execute a batch of operations like reading/writing from/to files as well as creating new ones. ...
0
votes
0answers
55 views

RS232 3rd party performance using C#

In my work i have an old fashion Vb app.. It's take single sale line(by text change event..) from the input and send it through RS232 output native. In purpose to get rid from any led display i took a ...
3
votes
1answer
96 views

Misra C, RTOS, and inter-thread communication

Currently I am developing an embedded system, running multiple tasks within an RTOS on a heavily constrained (mainly memory-wise) system. My team-lead advised the use of dynamic memory allocation. ...
0
votes
0answers
16 views

Best Way To Take multiple TCP Connectons, Read the Incoming Data, and send that Data back into the Main Thread in Golang?

I want to take data from my goroutines and add them back to the main thread/goroutine. Problem is that I need the goroutines to stay open because data can come through the connection at any time in ...
0
votes
0answers
59 views

C++ client-server design

The context I need to design a Client-Server(-Client) network in C++ that would allow an android application to communicate to a Raspberry Pi and back I am running everything on linux environment(s) ...
0
votes
0answers
60 views

Where to put use case calling threads in clean architecture?

I've just started using clean architecture, It's clean and nice, but I've found a bit confusing use case. My application should be able to register to update a token after some time, so I handled ...
0
votes
1answer
52 views

Multithreading with duplicate matrixes? [critique/insight wanted]

I'm working on a video streaming project for drones with opencv where I want to apply multiple stacked image manipulations on a 2D input matrix. I was advised to make all manipulations calls non-...
2
votes
1answer
44 views

How do i call an unreliable API over network? CompletableFutures vs try catch block in Runnable vs something else?

I have to call a critical API over a network (which makes it unreliable) many number of times in a go, many times a day. If the API fails to respond (timeout) or returns an error (because that server ...
0
votes
1answer
54 views

Should I separate send and receive methods into tasks for a CAN-BUS reader on ESP32?

I am developing a CAN-BUS reader (logger) with an ESP32 microcontroller. This sample uses RTOS and several task to send and receive CAN-BUS messages. https://github.com/espressif/esp-idf/tree/master/...
2
votes
2answers
117 views

Name of locking approach

I've seen this approach several times, both in async and multithreaded code. A counter is used to track asynchronous behavior or thread behavior - whenever a new action is started, the counter is ...
0
votes
3answers
117 views

Can a thread acquire another sychronized block if it already has a lock of synchronized block

So my question is if my thread A has acquired access to a synchronized method S1() can it acquire access to another synchronized method S2() or a normal method.
0
votes
0answers
40 views

Pausing threads calling the same method by making them try to lock an already locked mutex

I am confronted to a question regarding synchronisation between threads having shared data. This is a stripped down versino of my class : class Foo { private: boost::mutex m_mutex; std:vector&...
0
votes
0answers
60 views

How to send messages in the order they were queued, while ensuring that client B does not have to wait until client A has received his message?

I have a simplified producer/consumer pattern implemented below. The code outputs: "A" 1 second delay "B" 1 second delay "A" 1 second delay "B" ... What ...
1
vote
1answer
150 views

Throttling the factory function of a Lazy<T> instantiated with LazyThreadSafetyMode.PublicationOnly

When you use the constructor of Lazy<T> requesting the valueFactory and mode parameters (I mean this one) you can specify LazyThreadSafetyMode.PublicationOnly. This way you can prevent the Lazy ...
2
votes
2answers
97 views

Having tasks that can be ran individually or “in trees”, and each task can be blocking or non-blocking

I'm creating a framework that needs to execute certain tasks, I'll use building a car as an example for this. So, an individual task could be something like weld metal or screw bolt. But there are ...
0
votes
3answers
85 views

Ensuring Thread Execution Order when Writes Must Occur Before Reads

I'm currently designing a server with the following structure: A TCP thread pool that receives data from the network A queue that holds these requests A worker thread pool of a fixed size that takes ...
0
votes
1answer
133 views

Dealing with interrupt and sleep

I was thinking that I could calmly Thread.sleep() on an interrupted thread. Sonar doesn't think so, of course. In some circumstates we should waiting for conditions, even if an interrupt occured. Is ...
0
votes
2answers
177 views

Design choice to avoid lock contention

I have a network application F. It receives requests from one (or many) client network function. F can handle multi-client requests using an epoll loop. F maintains a state machine for each client(...
1
vote
1answer
160 views

Are JVM thread dumps a security concern?

When building parallelized applications using Java, a developer sometimes finds himself with a thread being blocked indefinitely because of a four-year-old bug in the spring-bean-web-rest-foo-bar-...
0
votes
0answers
113 views

multithreading - waiting on a condition without using locks (c++11)

i've been wondering about it for a while now but never found any answers. is it possible to use something like a condition variable without a lock? I have a vector of objects, and a thread pool, and ...
4
votes
4answers
1k views

How to check whether existing code base can deadlock

I'm improving/expanding a somewhat large code base, and I've introduced multithreading into it. But with the possibility of introducing code that could deadlock, which is nigh impossible to test for ...
3
votes
1answer
214 views

What is the typical best practice methodology around transferring money between two distinct systems?

I got this question on an interview the other day and was clueless to what the best practices are for solving it. It's the issue where you have to transfer money between two systems and want to avoid ...
1
vote
2answers
160 views

What do you call a class that can be disabled [closed]

Is there a design pattern that fits this description? A factory that creates classes that can be disabled and enabled. The users of the class don't know if the functionality is enabled or disabled--...
2
votes
5answers
503 views

If the whole point of recursion is to break the problem into multiple smaller problems, what if those problems were solved in parallel?

So I was studying here and I was thinking if the whole point of recursion is to break the problem into multiple smaller problems, what if those problems were solved in parallel? A quick search lead me ...
0
votes
2answers
62 views

Turn an asynchronous delegate pattern into a blocking method

I have to use a built-in API that works like this class MyAPIWrapper { func callAPI() { apiObj.delegate = self apiObj.doWork() // returns immediately, eventually calls self.delegate....
-3
votes
1answer
269 views

Is a physical thread a logical thread (a thread within a process) that a processor context switches to and processes?

What are the distinctions between physical threads and logical threads? The clearest definition of a physical thread that I understand so far is the one here: https://stackoverflow.com/questions/...
0
votes
0answers
89 views

How to setup up a background thread/task which triggers UI updates?

Background I'm designing a round-based game where one of the core design goals is to have a highly exchangable UI. For this, I've defined an interface which allows implementers to only focus on ...
3
votes
3answers
259 views

Why datatypes are marked as thread-safe instead of procedures?

In Rust, Send (or Sync) marker traits are used to indicate whether a value of a type (or a reference to that) can be worked on within threaded context. However, it is an attribute of a function or a ...
0
votes
0answers
39 views

How to communicate data from a threaded library?

Until recently I was involved in the development of a library to be used for acquiring data from a hardware device via a server application. The server application sends out messages via a ZMQ ...
0
votes
1answer
90 views

Multithreading - 2 active running threads calling each other without blocking itself

I have an implemented UDP receiver which is continuously receiving DTN packets (UDP encapsulated) and performing some operations on them. This whole process is working on a single main thread. However ...
-1
votes
1answer
201 views

Wait and wake-up vs. start and join for multithreading

A function that is repeatedly called should do multiple tasks: request a vector from a server. calculate a new vector. send this latter to a server. append the new vector summed to the downloaded one ...
-3
votes
3answers
190 views

Real-world analogy for green threads

I'm giving a talk on concurrency which will cover multithreading, multiprocessing and green threads. I'd like to give simple real-world analogies of single threaded programs, multithreading, ...
1
vote
1answer
749 views

One process using std::thread, 2 physical CPUs, 4 cores each, parallelism level?

Suppose I have a one C++ process, and I want this process to run eight threads in parallel. And suppose that: I have a computer with two (2) physical CPUs. Each CPU has four (4) cores, so that's 4x2 ...
10
votes
2answers
579 views

How could thread safety be provided by a programming language similar to the way memory safety is provided by Java and C#?

Java and C# provide memory safety by checking array bounds and pointer dereferences. What mechanisms could be implemented into a programming language to prevent the possibility of race conditions and ...
2
votes
1answer
244 views

Strategies for managing a dynamically sized pool of worker processes?

I have a problem to solve that's very much like a thread pool, and I was hoping to hear some strategies or find some resources to information on managing the size of the pool. Let's say I have the ...
3
votes
1answer
264 views

Design of file I/O -> processing -> file I/O system

I'm in the process of designing a new desktop application which is very different from other stuff I did before, and so I'll be happy if I could be pointed towards the right direction regarding the ...
1
vote
2answers
262 views

Notify Millions of subscribers at the same time(or with min. delay) in C++?

I'm working on a problem, in which i have some real time weather information of different cities through out the world. I'm exposing subscribe function to interested people/clients, with input:- ...
-2
votes
1answer
80 views

How to implement a CLI interaction with running java programm? [closed]

I would like your tipps about implemening a command line interface to interact with a running java application. Example: The Java Application is a webserver and a cli-client should interact with it: ...