Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
-2
votes
0answers
20 views

How Can I utilize GPGPU Cores Like I Do with CPU Cores? [on hold]

I have a 2D array and I want to run a single processing algorithm on each row. With CPU parallelism I can process, lets say, 8 row in parallel. Is there any way that I can use GPU cores for that? Lets ...
2
votes
2answers
84 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
68 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
0answers
58 views

How to control JavaFX's animations execution order when animations “queue” is being altered in run-time? [migrated]

What is the proper way of handling synchronization between GUI animations' execution order and the user's dynamic input? More specifically, I would like to know how to enforce some logical ...
0
votes
1answer
86 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
148 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
135 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
100 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
208 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
154 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
4answers
336 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
50 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
97 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
46 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 ...
2
votes
3answers
219 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
38 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
82 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
115 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
165 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
148 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
458 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
92 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
108 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
256 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
63 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: ...
1
vote
2answers
296 views

Why does the Thread Class implement Runnable interface

My question is that is there any reason for Thread class to implement Runnable interface by itself. Are there any specific use cases where overriding Thread makes more sense than implementing Runnable ...
3
votes
1answer
210 views

Why would CPython logging use a Lock for each handler rather than one Lock per Logger?

While developing my own logging library, I studied the source code of the standard logging module of CPython. One of its features is that handlers are thread-safe. One can write logs to a file from ...
7
votes
8answers
506 views

Unit test which asserts that current thread is the main thread

The question is does it make sense to write a unit test which asserts that the current thread is the main thread? Pros/cons? Recently I've seen the unit test which asserts the current thread for the ...
3
votes
1answer
177 views

Is a race condition with no downside still a race condition?

I am writing a piece of code which takes the difference between two numbers, finds that location in memory, and then sets the location to true. Currently my method of performing this is as follows. ...
0
votes
3answers
889 views

Can I produce a deadlock with a single thread? aka. What is a deadlock?

This expands on "Deadlock in Single threaded application" on StackOverflow. That question was not really conclusive and I think it better belongs here. By the definition of a deadlock, is it ...
5
votes
3answers
3k views

Is it okay to start a thread from within a constructor of a class

This is purely a design philosophy question in the context of C++. Is it a okay design philosophy to start a thread from within a constructor? I have a library whose sole responsibility is to ...
-1
votes
1answer
105 views

Synchronization method vs private final object for locking in java

Can anyone tell me which one is better approach between synchronization method and private final object in java and why ?? public class kclass { private final Object myObject = new Object(); ...
1
vote
0answers
43 views

UML how to model parallel activity with runtime-dependent number of participants

I want to model an activity that involves processing several items in parallel. So to speak, I want to find a Activity Diagram representation for something like the following snippet / pseudocode: ...
1
vote
0answers
25 views

Periodically update files from s3 in a Java maven library used as Packaged JAR

I have an application say x which uses another Java library(say Y) as a JAR file . So y basically needs to download a file and load it into memory before any of it's methods are called at runtime by X....
5
votes
1answer
241 views

How to document multithreaded applications

I'm working as a support engineer, having access to the source code, and I'd like to use this opportunity to document the source code, but I stumble on a first question: how do I even start? For ...
0
votes
2answers
111 views

C++, Threads, Classes and Conflicts

This is a concept related question. I'm writing a program polling for alerts on various devices, there are two different type of alerts i need to poll, reds and oranges. My approach is to create two ...
1
vote
0answers
108 views

How to use lock-free FIFOs in multi-threading?

Computer-science wisdom says that a lock-free FIFO (queue) is the right way to synchronize shared data between two threads in a lock-free manner. I know what a queue is and how the lock-free property ...
3
votes
2answers
977 views

Is the meaning of `const` still thread-safe in C++11?

I recently came across Herb Sutter's video from about how the meaning of const and mutable has changed in C++11 to mean bitwise const (and thread-safe, as a consequence) instead of the traditional ...
0
votes
1answer
201 views

How to design thread safe class when separating business logic from POCOs

I like to separate business logic out of POCOs into controllers. If an object must be thread safe, where do I put the lock code? In the POCO itself? Or in a controller? Might make sense because ...
3
votes
3answers
516 views

Multithreading ( thread per area ) for an MMO server, good idea?

As a personal project, I'm setting up a MMO, and writing the server in C#/.NET Core. As of now my architecture is as follows: The world exists of different areas ( you can go from area to area trough ...
1
vote
0answers
187 views

Daemon vs worker and when to use what?

(Note that, below, I am frequently using term "daemon or worker" just to indicate that I dont know which word to use as I dont know the exact difference between them in the context explained below.) ...
1
vote
0answers
175 views

Android Multiple Threads for I/O Operations in Room

I have a small example that i run on a real device with 4+4 cores. ExecutorService service = Executors.newFixedThreadPool(4); for(int i =0 ; i<1000; i++){ Runnable task = new Runnable() { ...
1
vote
1answer
99 views

Using python on a Raspberry Pi, how do I record video and keep reading other sensors simultaneously?

For my system I would like to record constantly, which independently I can do. Additionally, I need to be constantly reading some sensors (using SPI), which independently I can also do. My present ...
1
vote
1answer
85 views

Should this part of my web-app implemented on server-side or client-side?

I want to write an application which monitors a few URLs (like a couple hundred) of all branches of school. By monitoring, we mean that it sends requests to those URLs at regular intervals (Interval ...
2
votes
1answer
977 views

How would you design a “multithreaded” LRU cache using C++ (unordered_map and Linkedlist)?

Please note that this is about a thread-safe LRU cache (not simply a LRU cache as specified in https://leetcode.com/problems/lru-cache/description/). It isn't a duplicate of LRU cache design question ...
1
vote
2answers
702 views

Sequential or parallel access to hard disk in multithread program?

In multi threaded java program, I initiate four concurrent threads with below details 1. Thread 1 writing file F1 2. Thread 2 writing file F2 3. Thread 3 reading file F3 4. Thread 4 reading ...
0
votes
2answers
303 views

Design of a Python “service” using multiprocessing and threading

Due to the Global Interpreter Lock, multithreading in Python does not affect parallelism. This limitation is avoided in the multiprocessing library by spawning new processes instead. But threading ...
0
votes
2answers
77 views

Long response times vs. concurrency issues on a multithreaded web server

A class with a slow initialization used to process a request leads to long response times. But the actual method used is quite fast. Should the class be static, I guess it would need to process a ...
3
votes
2answers
1k views

Number of thread: Computation intensive vs IO intensive operations?

I came across below statement at this blog Computation intensive operations should use a number of threads lower than or equal to the number of cores, while IO intensive operations like copying ...