Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
2
votes
4answers
681 views

Multiple servers for each module or one server to handle requests from multiple clients

We got multiple devices that communicate over different protocols (rs232, tcp, http, etc.) and we want be able to send requests from multiple interfaces (as well get responses from each device to ...
1
vote
1answer
598 views

Accessing thread state from main process [closed]

I am currently writing a Python program with a main process distributing work to a number of worker threads via separate worker queues per thread. I am now having the problem that the main process ...
4
votes
0answers
72 views

Design synchronous wrapper around async process

I'm building a Spring-Boot API that will serve a system that requires synchronous behavior despite the API doing async operations. I'm not too familiar with threads and I'm thinking this might be the ...
4
votes
1answer
4k views

When is it safe to use Monitor (lock) with Task?

In a multi-threaded environment, we must consider concurrent access to writable resources. A common approach is to use Monitor or its shorthand form lock. Task is at a different abstraction level ...
-6
votes
2answers
817 views

How does the web application support 150 max threads when the cpu only supports 2? [duplicate]

doing an lscpu cmd this is what i get $ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 2 On-line CPU(s) list: ...
7
votes
2answers
2k views

Mutex vs Semaphore: How to implement them _not_ in terms of the other?

Recently I had to implement a Semaphore using a Mutex and a Conditional Variable (this combination is also known as a Monitor) for an exercise at the university: the Semaphore's decrement operation ...
3
votes
2answers
1k views

A multi-processing approach to listing the occurrences of words in a text file

A classical problem: read the words from a text file and list the occurence of each unique word in the file. I solved the problem using a hash map, but how could the performance be improved? I ...
1
vote
0answers
109 views

Background TCP server to collect data

I have an OpenGL application that plots data in real time. I would like to have a background TCP server that will accept data from a client without blocking on a call. The data is originally an ...
2
votes
2answers
1k views

Scheduling of parallel I/O-bound tasks (Backup solution)

I want to implement a backup solution in Python where a Backup-Server initiates backups on a number of virtual and physical servers (one server = one backup task). Disregarding the details of the ...
0
votes
1answer
167 views

Design improvement - C

Below is the design, that is implemented similar to design used in Linux/net/socket.c. Below design provide List abstraction, where, list.h provides List interface, show here Background: ...
3
votes
2answers
2k views

Difference between multithreaded programs on single and multiple cores

When programming using (pre-emptive) multithreading model on a single processor, we need to deal with synchronization, deadlocks, etc. Do any additional concerns appear (and correspondingly, new ...
6
votes
3answers
381 views

Why running threaded algorithms with exact number of cores the machine has, is faster than anything else?

I made some basic multi-threading tests here, and noticed that the speed increase when using the exact is bigger than I expected. I assumed that speed would increase linearly until I hit the limit of ...
1
vote
1answer
1k views

Multi-threading on a single core

Hypothetically, if you (I / someone) were to create a multi-threaded application, utilising the processing powers of multiple cores (for example, using TPL in C#). Would that program crash, if it were ...
3
votes
1answer
16k views

Parsing Multiple Files and Their Contents in Java using Multithreading without ExecutorService

I'm learning concurrency in Java and went over the tutorials on Oracle website. While I have understood some of it, a greater portion eludes me. I was thinking of a hypothetical problem (though it may ...
1
vote
1answer
237 views

How to design the system which executes two process independently with different configuration?

I have two process ProcessA and ProcessB. I want to run these two process independent of each other. There is no relation between them at all. Each process should have a different Properties object. ...
4
votes
1answer
373 views

Mutually exclusive concurrency C++

I'm writing a ray tracer and wish to add concurrency for the obvious (though likely small) performance gains. In my code I iterate over all the middle points in the grid of pixels that forms my final ...
2
votes
2answers
1k views

Parallel Image Processing Best Practices

When doing (possibly heavy) pixel processing on a large image, multithreading becomes a must. The standard practice is to initiate a loop whose indices are partitioned into multiple threads within a ...
0
votes
0answers
68 views

What (if any) would be a simpler way to structure this middle man thread/object

This my proposed structure for my C# program. My LIN Comms Object/Thread. Reads data from LIN, and fires two events (data received and data changed) then check to see if there is any in the write ...
2
votes
2answers
112 views

Get service data of future iterations

I have a doubt with threading data service calls within a foreach loop. Here it goes: Say you need to request data from a service and then process that data, for this example, let's say data request ...
-2
votes
2answers
234 views

Possible methods of accessing L1 cache and specifying threads/cores

A faster prime number generator with hyperthreading and L1 cache About five years ago I wrote a simple VB widget to generate the first one million prime numbers and then port them to into its single ...
0
votes
1answer
3k views

Executing a periodic Task with std::async

I am writing a class which periodically has to check, if the data it manages is too old, if so it should delete it. I am new to the C++11 multithreading library and I have the following questions: ...
3
votes
1answer
2k views

Producer/consumer problem with 2 mutexes?

The setup Let us consider a variant of the classical multithreaded programming problem: the producer/consumer problem. We have some finite number of resources (for simplicity, let there be just a ...
-2
votes
2answers
684 views

Does Multithreading help in web scrapping?

To my knowledge multi-threading is just an illusion since CPU schedules time for each of the process. So when scrapping at a particular time, only one content from the website will be scrapped and it ...
1
vote
1answer
438 views

Except for the fact that writing a userspace scheduler is hard, what are the disadvantages of M:N threading / green threads?

Recently I've been learning about the different ways languages handle concurrency under the hood, and would like to know a bit more about the shortcomings of M:N threading. Please forgive me if I get ...
6
votes
6answers
778 views

Am I looking at multithreading the wrong way? (Java)

This is a re-post from my question in StackOverflow, so here goes: For the past few weeks now I've been studying Concurrency(Multithreading) in Java. I find it difficult and rather different than ...
1
vote
1answer
4k views

How can create a list of tasks to execute synchronously on the same thread?

I am writing a program that controls some hardware via a serial port. The program will run various function based on user input. I need a way to queue these tasks and execute them synchronously on the ...
0
votes
2answers
87 views

technique to process a folder of files from several machines

There is a single network-shared folder of files that is to be processed by threads running on several servers. Once a thread starts processing a certain file, I don't want any other thread to ...
6
votes
1answer
3k views

Should I use a boolean or a cancellation-token to stop this task?

I have a program that starts a task as follows: token = this.tokenSource.Token; var t = Task.Factory.StartNew(() => { while(!token.IsCancellationRequested) { // do the work... ...
11
votes
5answers
2k views

How to prevent two users from registering at the same instant with same username?

We cannot serialize registrations as there are millions of users registering at the same time. Parallel registrations need to happen. Let's say the database doesn't contain username 'user1'. When two ...
2
votes
1answer
164 views

Implementation of solution for multithreaded resource sharing problem?

I am trying to figure out an implementation for a solution to a problem I outlined in another Programmers.SE question. I need to find a solution for this problem in C# most likely using the collection ...
0
votes
1answer
556 views

Is this class thread-safe?

I have an entity class package org.demo.stack; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class ...
1
vote
0answers
116 views

Trade off between concurrency and stagnation in a Dining Philosophers problem analogue?

I am currently facing a problem in the application I am developing that I think is the same as, or an analogue of, the Dining Philosophers Problem. In my application I have a list of N resources. I ...
1
vote
4answers
2k views

Best algorithm to multi-thread this application?

I define an algorithm to be best if it minimizes the total run time over commodity hardware (e.g. normal desktop and server PCs). I have sets A and B. I also have function f that works like f(a, b, n)...
2
votes
2answers
211 views

Would using coroutines improve my code?

I am currently developing my own programming language (written in Lua). The text analyzer is composed of two functions: lexer and parser. lexer takes as input a string, cycles over each character of ...
11
votes
2answers
4k views

How does sleeping a thread work?

When you sleep a thread, what is actually going on? I see that sleeping a thread "pauses the current thread for a given period of time". But just how does it work? According to How Thread.sleep() ...
3
votes
2answers
2k views

Not understanding the concept of how to make my GUI application

I am making a program that primarily deals with heavy data mining and analysis. It is primarily a back-end type algorithm, with no GUI elements or console windows seen as it runs. Occasionally though, ...
-2
votes
3answers
473 views

Is it possible and faster to run an application on an unused CPU core?

Is it possible to move an application (or task) to another core to make it run faster and get all of that cores processing power? The way I understand it is that in an operating system applications ...
1
vote
0answers
71 views

SonarQube Recommends Unsynchronized Class

I adopt a software architecture where I have one single data access in the persistence layer. Indeed, the persistence layer is a mere java application (JAR file) that I consider as an dependency, ...
1
vote
1answer
538 views

Producer and multiple consumers with limited types item

I am implementing producer-consumer where items to be consumed are of 1000 types type-0, type-1, ..., type-999. Producer inserts item of type-i in queue. Consumer uses that to update state machine ...
1
vote
2answers
127 views

Should I be Using a Thread?

I made a console application which makes the mouse click in the middle of the screen every two minutes. It has a while True loop in it which is meant to keep going for relatively long periods of time (...
1
vote
1answer
176 views

Proper way of empting deques with higher priorities with a threaded removal

I'm developing a producer/consumer system with three deques (each for one priority level, from max to min); first deque has major priority, so it must be read before others: once empty, others deques ...
2
votes
2answers
135 views

How do I know if I have to care about thread safety?

I don't know much about how computers work internally, so I also don't know much about multithreading, and when it takes place. I know it is important in databases or web applications and such, where ...
-1
votes
2answers
138 views

Designing an application with safe paralleled tasking

The title may have been a little vague... I am working on a piece of software that is designed to perform one task. I would like this task to work in parallel, allowing for multiple asynchronous ...
1
vote
1answer
148 views

Possiblity to request several Linux threads scheduled together (in the same time)

I'd like to be able to request Linux to schedule two or more threads in the same time. I mean today when my multi-threaded program is being executed I know that in worst case only one of my threads is ...
1
vote
1answer
735 views

How to test software with near-real-time requirements?

So, I've been refactoring my videoconferencing application for a while, covering it with unit and general tests. Finally, I got to the point where I need to write a loopback test with 1 client sending ...
0
votes
1answer
1k views

How to avoid nested Threads?

I often have a situation where I first need to do something in the UI thread (Android in this case), then to some networkstuff in an extra thread, switch back to the UI thread and udate the layout, ...
2
votes
3answers
1k views

How to make two threads interact with each other without stopping the execution of the thread?

This might sound similar to some of the other questions but it does not deal with wait or notify. I have two threads which do two different things The first forms a process in the background and ...
6
votes
3answers
3k views

How to properly deal with starvation

I'm trying to find a way to avoid starvation in my program, a producer/consumer (two threads, one for each role) problem with four priority levels (four deques). Basically, the consumer thread always ...
0
votes
1answer
76 views

Is it correct to say that threads enable programmers to expose process internals to the OS scheduler?

Is it correct to say that threads were invented to enable programmers to expose process internals to the OS scheduler?
1
vote
1answer
527 views

Multi threaded and event driven [closed]

I got this problem in an interview and want to confirm multi threading adds no value here. Case: You are writing an agent to buy stocks. The agent is initialized with a set of stocks to buy when ...

1 2 3 4 5 12