Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
0
votes
2answers
87 views

Approaches of splitting the same type of work among multiple threads in C++

I have a reinforcement learning project. For this I created a vectorized environment in C++, which is a handler for multiple instances of a simple game. It is highly parallelizable. Each worker can ...
1
vote
3answers
124 views

Do multiple software-threads on a single hardware-thread system execute sequentially?

I understand that if a system consists of multiple hardware-threads the scheduler assigns software-threads to hardware-threads. However, hypothetically, let's imagine a system that does only consist ...
0
votes
1answer
62 views

Thread-Safety with Enumerable collections and copies

Imagine I have an interface IHeapObject: interface IHeapObject { string Id {get;} SomeEnum Type {get;} } and it's implementation HeapObject: class HeapObject : IHeapObject { public string ...
4
votes
2answers
222 views

“Threads should only block on one thing” - is this a common best practice?

Context: Recently I was discussing the design of a small programme with a new team member (I am the product manager). The programme is essentially a protocol converter that reads data from a number of ...
-1
votes
1answer
103 views

How do social media platforms stay up-to-date with messages and posts? [closed]

This is a question I have always wondered Is it as simple as repetitive pinging of a server in a seperate thread or is it more complicated than that? I am only talking about the app version not the ...
3
votes
2answers
193 views

Hexagonal/Clean Architecture - threads, locks, synchronization

All the examples across the internet try to pretend that every application is run on a single thread. There is no problem with synchronization, multithreading etc. Uncle Bob, in his "Clean ...
0
votes
1answer
38 views

In an MVC-patterned app, how should one build the interface between model and user interface layers to work nicely with threading?

I am wondering about this. This is a sort of follow-up to my last question here: In the MVC pattern, what has the responsibility for creating the view? because now I've run into the question of how to ...
0
votes
2answers
195 views

My aproach to lockless concurrency

this is a highly theoretical question about my parallelization approach. First of all, I want to inform everybody that I do not claim that I am the 'inventor' of that approach but I couldn't find any ...
-3
votes
1answer
65 views

Will this time duration measurement in two threads give correct result?

A program I'm developing has two threads running similar but different task: thread1: timer1.start() writeToExternalDB1(consumedData) timer1.end() thread2: timer2.start() writeToExternalDB2(...
4
votes
4answers
156 views

How to understand the first and second readers-writers problems?

Computer Systems: a Programmer's Perspective says The readers-writers problem has several variations, each based on the priorities of readers and writers. The first readers-writers problem, which ...
-2
votes
1answer
62 views

How should functions that keep state across multiple invocations be made safe?

In Computer Systems: a Programmer's Perspective, 12.7.1 Thread Safety When we program with threads, we must be careful to write functions that have a property called thread safety. A function is said ...
2
votes
0answers
91 views

Why does the Java CompletableFuture API uses long + TimeUnit instead of Duration?

Java 9 introduced many new methods in the CompletableFuture API that support execution timeouts. For example: public CompletableFuture<T> orTimeout​(long timeout, TimeUnit unit); public ...
0
votes
1answer
48 views

How to subscribe to collection edits happening in a different thread?

I'll be using C# for my example since this is what I am using, but the problem is sort of generic. My app code takes a collection of Foos (externally populated and edited) to do some processing, and ...
2
votes
1answer
87 views

Effective thread usage under blocking scenario

I have the following scenario: I am listening file requests and when one arrives, I am starting download task in a new thread. After download task ends, a process task starts but this is important, ...
1
vote
1answer
69 views

Multi threading a database driven service

First some background on the problem, we have a windows service (C Sharp) that receives new messages and processes them.It is database driven so it checks a table for unprocessed records, processes ...
59
votes
10answers
20k views

Does it ever make sense to use more concurrent processes than processor cores?

I've got some process in Go. Here's an example counting lines in text, though the question is meant to be far more general than this particular example: func lineCount(s string) int { count := 0 ...
0
votes
1answer
45 views

System design to store pieces of data with specific ttyl to then refetch

I have a system which generates pieces of data that needs to be tracked and assigned a specific TTYL value (a value in seconds) for how long they are supposed to live before being re-processed. I ...
-2
votes
1answer
105 views

How to do achieve parallelism in a console application

I have a .net web application, let's say A and a .net console application, let's say B.In A, I have a queue with multiple jobs to be done by B.Once I select the jobs from A, a queue gets created. Each ...
0
votes
0answers
28 views

Is JTA appropriate for concurrent loads to a single database and transaction?

I have a Java process that loads data from a file in to an RDBMS - basically a CSV import with some logic around updating and deleting records in addition to the inserts. It's important that it ...
2
votes
1answer
101 views

What is the best way to decouple and define the orchestration (coordination) of concurrent tasks?

I have a data synchronisation concurrent algorithm. It does the following: get data and files from server, send data and files to server, save them to database / filesystem. Imagine the system like ...
0
votes
0answers
12 views

How to use UDP MulticastSocket for Reception with ThreadHandler-Looper-Handler in Android

I am trying to find the right architecture to be able to listen to UDP Multicast socket, receive the datagram packet that is in JSON format and then send the data to my BroadCast Receiver. It is ...
7
votes
9answers
2k views

Why is multithreading not used everywhere?

Not almost, but all modern CPUs have multiple cores, yet multithreading isn't really that common. Why to have these cores then? To execute several sequential programs at the same time? Well, when ...
0
votes
1answer
120 views

RxJava and race conditions

I have seen some RxJava projects using multithreading with .subscribeOn(Schedulers.io()), and their .subscribe(() -> {...}) code is manipulating some data structures that are also processed by ...
0
votes
0answers
95 views

How can you multithread an html parser [ in C++ and similar languages ]?

Ive done two HTML parsers. Done with Regular Expressions [that accounted for nesting]. It was quick, but error prone. Done by evaluating Character by Character through switches. Here was the basic ...
0
votes
0answers
22 views

Using coroutines dispatchers as executor

We can use coroutines dispatchers as executor like Dispatchers.Default.asExecutor() and we do it when we want to use a coroutine just as a executor for operations in application lifetime like ...
0
votes
0answers
108 views

Creating a microservice REST api to offload CPU intensive tasks from node.js

I am building a game which has rooms with clients connected. Each room has it's own websocket. At the end of the game, some calculation needs to be made about who won and it's a complicated math CPU ...
1
vote
1answer
76 views

How to represent this multithread application?

I am having trouble trying to represent some multithread process and I would appreciate some advice. Please let me explain this with code. (in C++'ish because that is what I am familiar but ...
0
votes
0answers
40 views

GoLang concurrency model - Using context

I learnt that, the reason we have context(P) introduced in Goruntime, is that we can hand them off(it's LRQ of goroutines) to other OS thread(say M0), if the running OS thread(M1) needs to block for ...
-2
votes
2answers
396 views

Generating unique numeric ids in multiple thread application without locking

Multi Threaded application with n threads implemented using ExecutorService. There are x (tens of millions) tasks submitted to the ExecutorService. Each task needs to generate millions (number of ...
-1
votes
1answer
156 views

Do other languages have variables shared between threads?

I guess it would be too complex for Node.js / JavaScript to leverage, but I've been working with clusters in node to break big tasks down so all cores can work at once but the inter-process messaging ...
0
votes
0answers
32 views

Porting a SYSV IPC multiprocess architecture to Windows

I'm looking at porting a Unix-based multi-process architecture server application. The app uses SYS V IPC shared memory and semaphores. It has a main message queue in shared memory, with semaphores ...
-2
votes
1answer
219 views

How can I represent with UML a process that involves queues?

I would like to use UML diagrams to show some processes I am designing and would like to implement. The processes involve using a queue, and adding and taking out elements from it. In one of this ...
0
votes
2answers
216 views

Which UML diagram is more adequate to represent a multithread process with loops

I have a process that I have been able to drawn somehow with a flowchart. This process involves several classes, loops and several threads of execution. However I am unsure which (if any) UML ...
-3
votes
1answer
72 views

Methods for reliably benchmarking own program's run time

I'm writing a basic password cracker in C as an introduction to multithreaded programming. I've implemented this already using a 'parallelization' approach that spins up a set number of threads and ...
2
votes
3answers
178 views

Should services in a service layer be thread safe?

This is for an Android app, but I think the question applies to any software designed with a service layer. Our app is structured with a presentation layer that handles the UI and a service layer ...
3
votes
3answers
290 views

How can I improve the speed of scanning multiple directories recursively at the same?

So I am trying to speed up my program by using concurrency and/or multi-threading and/or process parallelism. The topics are pretty complex and I am sort of new to them so I am still trying to figure ...
0
votes
1answer
66 views

Handling background tasks that may not be relevant when they are completed

Imagine the following pattern: you have a window with information that needs to be updated asynchronously. You launch and detach a thread to handle fetching the information, but while the information ...
1
vote
1answer
194 views

Long running REST API in PHP, async?

I have a RESTful API built with PHP. In POST request saving to DB is triggered. The problem is that now I have to support long running tasks. For example a user triggers POST request that is going to ...
0
votes
0answers
24 views

How to design data persistence in an application which stores data-streams from multiple clients

I'm developing a data consumer application in C# which connects to multiple remote clients over TCP. Since it's C# application, each client is monitored by a Task whose purpose is basically to run a ...
0
votes
1answer
111 views

Worker pool running tasks of the same kind serially

I would like to run tasks in parallel. At this time, I am using a very simple worker pool using a single concurrent queue shared by all the threads. Every task has a non unique "tag" (an integer in ...
5
votes
5answers
886 views

Performance: Is There a Reason to Use Processes over Threads?

This is a general question but I work in the .NET world so I'd like to know if there any specific quirks about the .NET Framework / Core platforms that I should be concerned about here. I think it's ...
1
vote
2answers
36 views

Multiple thread invocation in Rest Web Service

I have a scenario in our Web Application. GUI invokes a REST web wervice and further web service calls a procedure. However, the procedure returns data properly for most of the scenarios. In some ...
1
vote
1answer
64 views

Is my server design safe regarding multiple threads and concurrent database reads/writes?

I'm making a chat server using sockets and a MySQL database, and after it's working I want to expand it to become a more complex game server. I want to know whether my design is missing anything. ...
1
vote
1answer
88 views

What are the limitations of WinSock2 sockets within threads?

So I've run into some strange behavior on an application i'm developing in C using the windows API. Im trying to implement a closed connection server-client interface. However, for whatever reason ...
0
votes
0answers
107 views

How to design a fast way to `unarchive` file using python?

Assuming the following scenario: A python application that receives file and process that file trying to understand what the file format( any type of data/compressions/archives/packages/mounts/etc ),...
4
votes
4answers
174 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
613 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
24 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
123 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
129 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 ...

1
2 3 4 5
13