Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [multithreading]

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

-1
votes
0answers
29 views

RealTime Parallel DSP (Digital Signal Processing) in Java [on hold]

Hi, I have a project of DSP, Multi Thread in Standalone, using Java. I have a Sound Receiver, it is a single Capturer and pass data in Wav format, I selected 8KHz for Sampling Frequency 1 Byte per ...
0
votes
1answer
81 views

What are the counterparts of the asynchronous model compared to the thread model? [closed]

According to this article: http://krondo.com/in-which-we-begin-at-the-beginning/ The asynchronous model is always better than the thread model, since it achieves the same, consuming less resources, ...
3
votes
1answer
194 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
151 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
292 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
48 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
82 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
41 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
204 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
78 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
91 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
147 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
120 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
433 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 ...
3
votes
1answer
63 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
98 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
253 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
58 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
250 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
157 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
396 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
176 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
649 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
2k 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
91 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
40 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....
4
votes
1answer
213 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
107 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
82 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
778 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
185 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
500 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
174 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
152 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
87 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
748 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
539 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
246 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
76 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
813 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 ...
5
votes
4answers
258 views

Should I inject a Thread.sleeper as a dependency to make unit test easer?

I have a repeated pattern in my code that is not easy to test: classes that execute periodically. Just to simplify things lets say assume something like: while( running ){ long millisToWait = ...
1
vote
0answers
775 views

Using a Boolean to cancel thread

I asked a similar question to this on SO, but after re-reading it this morning, I realized it wasn't clear what I'm asking. So I narrowed down my problem and realized it was about a pattern instead of ...
2
votes
2answers
163 views

producer-Consumer with Signaling Architecture in a Real-Time Operating System (RTOS)

I'm developing a real-time system by making use of an mbed-OS (RTOS for ARM architecture). I'm not a software engineer and I want to know whether the following solution is practical or not, and how to ...
0
votes
2answers
102 views

Struggling with implementing synchronization or concurrency

In my app two components A and B, have their data and state based on the data and state of a 3rd component, component C: Both A and B can change the data of component C. Both A and B listen to ...
1
vote
1answer
261 views

Embedded Systems: Designing an API that monitors an address

This question was tossed as a starting point in a technical interview at a semi-conductor company. I guess there are no right ans - the purpose of this open ended question is to gauge the engineer's ...
0
votes
0answers
319 views

Examples for bidirectional and unidirectional relationships between objects

To better demonstrate the difficulties of reading/updating objects in a multithreaded environment, I'm looking for examples for groups of objects with a bidirectional or unidirectional relationship ...
3
votes
1answer
416 views

What tasks does a memory barrier enforces other than preventing the re-ordering of instructions?

I know that a memory barrier prevents the re-ordering of instruction from before to after and from after to before the memory barrier, for example if I have the following instructions: instruction 1 ...