Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
-2
votes
2answers
238 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
775 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
547 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
1k 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
5k 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
107 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
175 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
686 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
122 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)...
1
vote
2answers
247 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 ...
20
votes
2answers
6k 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
583 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
77 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
555 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
129 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
184 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
186 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
171 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
855 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
2k 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
4k 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
610 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 ...
2
votes
1answer
2k views

What are the pros and cons of using these Multithreading Models in a Client/Server Architecture

In my classes of parallel programming the teacher mentioned three models, dynamic thread creation (create threads according to demand), thread pool (create a fixed amount of threads) and mixed or ...
0
votes
1answer
17k views

Using database connection on multiple threads

let's say I have a database connection in the class Database which offers the following public methods public synchronized void open() {} public synchronized void close() {} public synchronized void ...
4
votes
1answer
2k views

How to signal a loop to continue the execution instead of using sleep

I am trying to create a thread that will sit and wait to detect new objects in a vector (the queue). Using a loop will crush the resources on the given machine, so I am trying to figure out how I can ...
2
votes
1answer
5k views

Collect and prcess data from multiple threads in Java

There is a Java program that reads a list of orders and for each order starts a thread that receives data from SQL and prints the list of items in a given order to an order_name.html. I want to write ...
20
votes
2answers
10k views

Do compilers utilize multithreading for faster compile times?

If I remember my compilers course correctly, the typical compiler has the following simplified outline: A lexical analyzer scans (or calls some scanning function on) the source code character-by-...
4
votes
1answer
538 views

Potential legal issues with lock-free / wait-free structures / algorithms

While researching the subject matter - lock-free and wait-free data structures - I'm seeing a worrying amount of mention of patents with this area. I've hobby-researched compression algorithms years ...
0
votes
2answers
3k views

Why a thread uses a stack in a context switch?

Correct me if I'm wrong, but if I have an operating system that makes a context switch, then that context switch is in practice a switch from one thread to another, where one thread was running one ...
4
votes
1answer
962 views

Monitor.Enter() when a thread is of highest priority

Background Okay, so let's say I have some high priority (ThreadPriority.Highest) thread t which needs to enter a critical region in order to consume some data. I will use the following code snippet ...
1
vote
2answers
3k views

multi-threading performance when CPU is maxed out

I've noticed my software severely degrades when the # of threads is substantially increased. What I mean is that when I limit the # of threads, the performance is much better than when I just let them ...
4
votes
2answers
3k views

How to facilitate thread-safe access to large set of shared variables?

I have 2 sets--inputs and outputs--of 70 32-bit integer variables and 70 bools (140 vars altogether). These need to be accessed and modified from 3 threads. What is an appropriate design pattern to ...
5
votes
1answer
2k views

Is there use case for implementing a callback if a future is returned?

If I have function which returns a future, is there any reason to also include a callback where the callback is simply called right before the future completes? The only advantage I can think of ...
7
votes
8answers
1k views

How does immutability remove the need for locks when two threads are trying to update the shared state?

Okay so I read through this: Does immutability entirely eliminate the need for locks in multi-processor programming? And this was the main takeaway for me: Now, what does it get you? Immutability ...
2
votes
3answers
1k views

Do I have to fork a server program as an “C” child process in order for correct interprocess communication to take place?

I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ ...
2
votes
1answer
1k views

How to design a dynamic thread allocator

Forgive the title if it isn't correct, I am just not sure what I am trying to design is called. Say I have a number of tasks I want to run, N. Additionally, I have a maximum number of threads I can ...
51
votes
8answers
12k views

What are the drawbacks of making a multi-threaded JavaScript runtime implementation? [closed]

I've been working on a multi-threaded JavaScript runtime implementation for the past week. I have a proof of concept made in C++ using JavaScriptCore and boost. The architecture is simple: when the ...
5
votes
2answers
679 views

Why is threading platform-dependent?

I am reading book "Foundations of Qt Development", Chapter 12, and I read that threading is platform-dependent, can someone explain, why? I know how to use threads but that what they said is not so ...
-1
votes
2answers
1k views

Which is better either creating two objects for two threads or one object for two threads?

In the below program, I'm calling method1() of SampleClass from two threads. So, basically I have created two objects for each thread and called the method1(). I have also seen the scenario of ...
-1
votes
2answers
160 views

Lock threads or not lock threads?

I have an application (full-stack) that is used millions of times concurrently. Some vital application properties are managed on the client side (at the time it seemed to be the simplest approach to ...
1
vote
1answer
182 views

«Heavy» object initialization: within each thread or outside and then pass it to the threads as parameter?

Let say there is an array of strings, I have to process. I'm using a «heavy» third-part object which gets the string and performs its analysis. In order to optimize a performance, I create a number of ...

1
3 4
5
6 7
13