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.

1
vote
0answers
35 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
200 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
78 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
414 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
119 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
66 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
23 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
53 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
82 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
122 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
106 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
81 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
68 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 ...
2
votes
2answers
196 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
200 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
162 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
1answer
71 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
95 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
80 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
97 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
234 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
402 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
199 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
293 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
50 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
198 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 ...
3
votes
2answers
1k 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
400 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
592 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
84 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
289 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
1k 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
40 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
448 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
68 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... (...
3
votes
1answer
1k views

How are queues made thread-safe in Python

I admit this was asked to me in interview a long time ago, but I never bothered to check it. The question was simple, how does Python make Queue thread-safe? My answer was, because of Interpreter ...
2
votes
0answers
330 views

How to dispatch these functions in Objective C to not lock Main thread?

There's a large shared object (kind of OpenGL context) in my project. It is accessed from multiple threads. To ensure only one thread at the moments is using SHARED_OBJECT, mutex (kind of ...
1
vote
0answers
108 views

How to decouple a message broker and its message handlers?

Project description: I have a nodejs project where I try to build a bluetooth mesh like network, each node consists roughly of 4 parts the frontend part, the message broker, a bluetooth client and a ...
1
vote
1answer
359 views

Multiple API calls potentially spawning multiple Websockets - Threading vs Async

I am designing a program with the flow as outlined below. Note, these are all network calls, there is no system I/O (hard drive). Initially, multiple independent API calls need to happen - they don'...
0
votes
1answer
68 views

Mqtt multithreaded Java app

I have a Java app which acts like a command server for other devices and communicated with them via MQTT. I want to add a new functionality and don't let my sender class (implemented as a thread) send ...
0
votes
0answers
44 views

Design a service that takes a job and perform operations after certain time lags

Scenario: Consider a 'listener'(service) which is ready to accept a job and then waits for x minutes after which it must send an email after checking something from database. If the db condition is ...
5
votes
2answers
4k views

What construct do I use to guarantee 100 tasks are running in parallel

I was trying to create an integration test for my service where 100 clients would connect, login, send request, and log all responses for some configurable amount of time. I was build a class for ...
5
votes
1answer
165 views

Immediately awaiting an asynchronous call [duplicate]

While working on an inherited project, I noticed the original dev(s) created many asynchronous functions that never seem to take advantage of being, well, asynchronous. For example: // The async ...
4
votes
1answer
718 views

Enhancing the quality & performance by opting for multiple tasks vs single task?

I'm trying to improve the performance, code quality and just make it better in terms of practice overall. I have a server for a game that managers all users connected as well as things like objects ...
0
votes
2answers
1k views

One thread for all database operations or one thread for each db operations?

I am working on a server application that should handle many requests. There is one thread per each request and each request has a Database operation. Creating connection for each request and doing ...
1
vote
2answers
211 views

Good practice to store runtime data

Cheers guys, I am quite new to C++, however, I have some years of experience in programming and I am open for challenges :-) Currently, I am designing a "small" scientific program to perform some ...
1
vote
2answers
928 views

How do I get a program designed to run continuously (converting data on a Serial COM port) to exit?

Problem Statement I'm writing a C# console program that takes binary data coming in through Serial COM1, converting each byte into ASCII hex, and then outputting those HEX characters out through ...
0
votes
1answer
74 views

Does placing an httpd server in front of a Vert.x application defeats Vert.x's purpose?

I'm watching a talk on Vert.x (not in English) and they say that "the whole architecture needs to be asynchronous from beginning to end", and cites as an example of what not to do putting an Apache ...