Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
145 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
62 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(...
3
votes
4answers
99 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
55 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
87 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
47 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
85 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
67 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
103 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
27 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
94 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
5 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
75 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
78 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
19 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
72 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
74 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
36 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
165 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
124 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
21 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
137 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
123 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
70 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
146 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
206 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
63 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
129 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
87 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 ...
6
votes
4answers
644 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
62 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
78 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
100 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
465 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
19 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
121 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
109 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 ...
5
votes
2answers
699 views

Is it good approach to await async tasks in object destructor?

I'm currently working on class with some async tasks under the hood. In fact I need to delegate few tasks to asynchronous execution and be sure that all of them are finished before class was destroyed,...
2
votes
1answer
110 views

Parallel execution: 1 thread pool or N thread pools?

I have a tree generated by configuration. Each leaf of the tree is a long running task (like DB query, reading from file, etc.) that gives a result I want to store in a mirrored tree with only the ...
0
votes
3answers
172 views

How do you optimally and securely isolate processes when building an operating system from scratch?

I am trying to build software in JavaScript that emulates an operating system. For all intents and purposes, it is an operating system, even though it is JavaScript and we are running in the Node.js ...
0
votes
3answers
377 views

Multiprocessing vs multithreading

During my last job interview which was about half year ago, the technical guy asked me, whether the better option is to use e.g. 100 processes to do some work, or only one process but with 100 threads....
6
votes
5answers
2k views

Implementing a hash table with true concurrency

This was recently a question I was asked in a screening and it got me thinking. I never totally settled on how the conversation ended, and I did some digging. None of the answers I saw seemed ...
0
votes
1answer
75 views

Launch threads continuously with predefined interval between threads

I'm currently using a third-party API to fetch results, using a REST client (Retrofit). The problem is that the amount of requests per second that I can do to the API is limited with interval: I can'...
-2
votes
1answer
76 views

Does accessing RAM from 2 threads double access time (synchronous access)?

As in topic. If i want to access RAM from 2 different threads, completly different cells in memory, do they queue and are sent asynchronously or queue? Lets say accessing memory from one thread (...

1
2 3 4 5
13