Stack Exchange Network

Stack Exchange network consists of 174 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.

2
votes
2answers
168 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
52 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: ...
0
votes
1answer
76 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
110 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
324 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
168 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
208 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
424 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
58 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
24 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
23 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
154 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
100 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
41 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 ...
2
votes
2answers
364 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
174 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
462 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 ...
0
votes
1answer
223 views

`set-then-get` vs `get-then-set` in context of race condition?

I have recently came across approaches to set-then-get and get-then-set in context of race condition in multithreading. My understanding :- set-then-get is the same approached in java concurrent ...
1
vote
0answers
104 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
93 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
63 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
84 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 ...
0
votes
1answer
302 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
280 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
183 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
71 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
411 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
209 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 = ...
0
votes
0answers
442 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
123 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
0answers
193 views

Multi-threaded socket chat server design

I've a general question about the design of a multi-threaded chat server application written in Java. At the moment I've the following structure: ConnectionController class which handles the I/O ...
0
votes
2answers
90 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
141 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
262 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
406 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 ...
2
votes
2answers
201 views

Reading huge (up to 32 GB) file in multithreading env?

Goal: 1) huge file read in chunks each 1 MB long, 2) each one gets compressed and written to an another output file. Note: I am limited to .Net 3.5 only. Is there a known pattern how to parallelize ...
2
votes
2answers
473 views

What is an “active thread” in Java?

From this discussion, there are two opinions of what Thread#activeCount() returns. An "active thread" is actually executing bytecode. It is a thread that was started and is not waiting on IO or on a ...
0
votes
0answers
65 views

.Net - “Thread is blocked/waiting” meaning for I/O bound operation

Caller waiting for method to return back and till it is not returning, we can say thread is waiting, right ? However, this behaviour is because that inner method is waiting for some other operation or ...
0
votes
2answers
229 views

copying of memory vs pointer to memory in real time systems

While working in a multi-threaded environment, then data sharing seems to be a good option to pass data between threads. While working with real time systems it is apparently advisable to go with ...
4
votes
2answers
2k views

Best practice for exception handling in Java threads

long-time reader, first-time asker here. I have a service which writes data to a database in batches. It contains a buffer which is being watched by a separate thread. Whenever the buffer reaches a ...
1
vote
1answer
490 views

Using inner classes to achieve thread-safe behavior without synchronization

I have some classes that contains both immutable (primitive & references) and mutable data, but mutability come from external writes (another process). To avoid using synchronized on every ...
0
votes
1answer
843 views

Is it better to listen on multiple ports than listening on single port?

In my server, I have 1000 threads that are listening to 1000 different UDP sockets. When a thread receives a packet it puts the UDP packets on a thread-safe queue. The code is like this. while(...
1
vote
1answer
87 views

Architecture for working with several devices

I create an application for a system, which consists of several different devices, each of which should be controlled by a computer via one of standard hardware interfaces and could be accessed via ...
1
vote
0answers
292 views

Inter-system communication design on Windows (C++)

I was wanting to create a program consisting of 3 elements: A central component with no UI which will work on HTTP traffic and trigger one or more “worker” elements as needed A monitor component ...
0
votes
1answer
80 views

Is there a better approach for mass balances processing

My task is to process asynchronously balance deltas for multiple clients and provide aggregated balance amounts. I have a REST service which accepts requests from N clients C₁…Cₙ, each of them has ...
2
votes
1answer
2k views

How to handle multiple calls to webservice?

I got a REST webservice and it has a simple method like; public void processItem(Item item); Problem is processItem method takes too long to complete nearly 1 minute) and there can be multiple calls ...
3
votes
1answer
192 views

Simple solution for calling a function only on one thread, queuing waiting calls?

Let’s assume there is a function EventHandler that is called on multiple threads at different points in time. EventHandler has to call SomeOtherFunction, but these calls shall only happen on one ...
0
votes
0answers
41 views

Patterns for pre-emptive background work scheduling

Here is problem I hope the community can help me analyze: I want to execute a set of jobs with one background worker (or several). Whenever a job is done, a message is fired, and a listener on the ...
4
votes
2answers
597 views

Threaded batching algorithm

Ok, I'm working on DynamoDb-based caching. We have an API where each call costs us real money and the information retrieved is "fresh" for 2-3 weeks, so it makes sense to cache it. There's no ...
0
votes
0answers
80 views

Best software architecture for a PC application with a number of short and long running tasks

This is probably going to expose my lack of software experience but I'm looking for advice on a suitable software architecture and mechanisms (threads etc.) by which I can achieve the following... (...