Questions tagged [multithreading]

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

Filter by
Sorted by
Tagged with
8 votes
2 answers
5k views

Concurrency pattern of logger in multithreaded application

The context: We are working on a multi-threaded (Linux-C) application that follows a pipeline model. Each module has a private thread and encapsulated objects which do processing of data; and each ...
Dipan Mehta's user avatar
  • 10.6k
8 votes
4 answers
12k views

Threads or ThreadPool? Fixed or Dynamic ThreadPool?

I have a java program which listens on a port for input. Based on Input, it calls a webservice and then returns a success/failure back to the client program. I fork a thread for each client ...
user93353's user avatar
  • 441
8 votes
3 answers
1k views

Is it safe to rely on static analysis to "reproduce" concurrency bugs reliably?

I've inherited some Java code which I suspect harbours some concurrency bugs when synchronizing between a thread that queries data and an IO event that updates the same data. I'm trialling a static ...
doughgle's user avatar
  • 191
8 votes
4 answers
3k views

How to prevent others from using non-thread safe variables in a multithreading environment?

I have an application written in C++ that was originally single threaded, but, due to the increasing complexity of this project, I'll need to expand it to at least two or three threads. There are ...
Anonymous Penguin's user avatar
8 votes
6 answers
433 views

When developing a piece of software, when do you start thinking/designing the concurrent sections?

Following along with the principle of not optimizing too early, I'm wondering at what point in the design / development of a piece of software do you start thinking about the concurrency opportunities?...
Stephen's user avatar
  • 2,131
8 votes
1 answer
6k views

Parallel programming library? (+ some features)

Note: this is a reposting as the question has been considered non-suitable for the Stack Overflow forum and should have been posted here. The original topic is there. I'd like to talk of ...
Ceylo's user avatar
  • 183
8 votes
1 answer
1k views

How to document multithreaded applications

I'm working as a support engineer, having access to the source code, and I'd like to use this opportunity to document the source code, but I stumble on a first question: how do I even start? For ...
Dominique's user avatar
  • 1,766
8 votes
2 answers
362 views

Are Concurrency Abstractions Emulating UNIX Processes?

OK, I was pondering this today, and I've come to ask for completely subjective and bias opinions on it. Paradoxically, despite this, I don't think it's flame-war fodder either. I think there is room ...
Louis's user avatar
  • 287
8 votes
1 answer
1k views

Alternatives to Pessimistic Locking in Cluster Applications

I am researching alternatives to database-level pessimistic locking to achieve transaction isolation in a cluster of Java applications going against the same database. Synchronizing concurrent access ...
amphibient's user avatar
  • 1,591
7 votes
2 answers
2k views

How to do thread management in C++?

We use pthread for thread management in C based systems. pthread is in general compilable by C++ compiler (like g++). However, what are the better ways of abstractions for threads in C++? Also, for ...
Dipan Mehta's user avatar
  • 10.6k
7 votes
1 answer
419 views

Can functional programming languages have deadlock conditions?

I am reading through "Clean Architecture: A Craftsman's Guide to Software Structure and Design" and it says that: All race conditions, deadlock conditions, and concurrent update problems are ...
Quantum Guy 123's user avatar
7 votes
2 answers
8k views

Why would one ever want to use a synchronized method in Enum?

I stumbled upon this question and a couple of other along the same lines. While we know creation of enum is thread safe and enums are by birth singletons . It kind of confuses me that why would ...
Shahzeb's user avatar
  • 310
7 votes
1 answer
576 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 ...
8protons's user avatar
  • 1,369
7 votes
1 answer
18k views

Thread.State BLOCKED vs WAITING

What is difference between the BLOCKED and the WAITING states of a thread. As per JAVA code comments /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in ...
Free Coder's user avatar
7 votes
2 answers
19k 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 ...
JohnEye's user avatar
  • 300
7 votes
4 answers
3k views

Testing thread safety

Say you have a function f that is or contains a critical section. How would you unit test that only one thread can run it at once, that it doesn't have race conditions, and that it doesn't cause a ...
Edward Strange's user avatar
7 votes
1 answer
2k views

How does condition_variable::notify_one() choose which thread to unblock?

notify_one() of C++ 11 thread library is used to unblock one of the waiting threads. How does it choose which thread to unblock? To begin with, I tried googling but could not find any appropriate ...
AbhinavG's user avatar
7 votes
2 answers
5k views

Is there such a thing as too much asynchronous code?

I am at the moment messing around with clients and servers in C# winforms and I'm trying to implement it all asynchronously. However, I'm beginning to wonder, should I use asynchronous code for ...
Ryan Peschel's user avatar
7 votes
2 answers
7k views

How to parallelize a sequential algorithm?

What thought process should one follow to convert a sequential algorithm to a parallel one ? Are there any specific code pattern that can be parallelized. Some patterns that I normally use are: ...
Saurabh Saxena's user avatar
7 votes
3 answers
33k views

Multi-threading in C# .NET Windows Service

I am writing a Windows Service (using C# .NET 3.5 VS2008) and my requirement is: When the Windows Service start - it performs record check operation (in Database) @ every 30 second interval (I have ...
Ankit Shah's user avatar
7 votes
1 answer
4k 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... ...
Snoop's user avatar
  • 2,748
7 votes
2 answers
494 views

How to maintain synchronised state across threads - is this a good use for a Singleton?

I hear a lot about "Singletons are always bad" around the place. I don't hate on them to that degree but I try not to use them if I have a better alternative. In this case I have a system that ...
glenatron's user avatar
  • 8,709
7 votes
4 answers
2k views

Command-Query-Separation and multithreading safe interfaces

I like the command query separation pattern (from OOSC / Eiffel - basically you either return a value or you change the state of the class - but not both). This makes reasoning about the class easier ...
Tobias Langner's user avatar
7 votes
2 answers
523 views

where can I find an overview of known "multithreading systems architectures" design patterns? [closed]

Using C#, I have been doing multithreaded development for about 5 years, and consider myself quite proficient (I wrote my own lock-free queue and task parallel framework before Microsoft made TPF). ...
JasonS's user avatar
  • 193
7 votes
3 answers
7k views

How many threads should access the file system at the same time?

We have a module in an application which stores data in multiple files and multilevel directories and access them from multiple threads (both reads and writes). The directory structure is based on a ...
usr95's user avatar
  • 71
7 votes
2 answers
2k views

Advice for designing API request rate limiter?

I'm in the planning stages of a web application that makes heavy use of data retrieved from a third party's REST API. This data is cached on the server and requested by clients via AJAX. The REST API ...
TseehnMarhn's user avatar
6 votes
3 answers
28k views

Best way to define, start and stop threads in C#

I am making a little program, which have few Threads, constantly running. At some point, I may want to stop one of them, and then, after random period of time, to start it again. So first, what is the ...
Skaidar's user avatar
  • 77
6 votes
6 answers
2k 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 ...
Mr. Nicky's user avatar
  • 179
6 votes
4 answers
15k views

Problems of multiple threads sharing/accessing the same data [closed]

I have been researching into when data is being accessed or shared by multiple threads within Java. And looking into the problems such as: Thread Interference Memory Consistency Deadlock Starvation ...
Frank_B's user avatar
  • 69
6 votes
5 answers
4k views

Cloud computing platforms often default to one CPU. Does this mean I shouldn't use Parallel Programming?

Almost every cloud instance I can find defaults one CPU. Why is this only one CPU now, and should I expect this to increase in the future? Does this design impact my code design so that I exclude ...
makerofthings7's user avatar
6 votes
5 answers
2k 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 ...
Christian Findlay's user avatar
6 votes
3 answers
5k 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 ...
elmazzun's user avatar
  • 281
6 votes
2 answers
18k views

JUnit Testing in Multithread Application

This is a problem me and my team faces in almost all of the projects. Testing certain parts of the application with JUnit is not easy and you need to start early and to stick to it, but that's not the ...
Sebastian van Wickern's user avatar
6 votes
3 answers
478 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 ...
speeder's user avatar
  • 657
6 votes
2 answers
8k 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 ...
user3198603's user avatar
  • 1,896
6 votes
1 answer
6k views

Threads: the difference of concurrency between many-to-one model and one-to-one model

I am studying "Threads" part with a textbook, Operating system concepts written by Abraham Silberschatz, Peter, Greg. First, I'm going to say something in the textbook related to my question, and ...
Danny_Kim's user avatar
  • 241
6 votes
1 answer
3k views

When to use coroutine over generator?

Pipeline processing of data can be done either, using generators only Example generator in pipeline: def grep(source, pattern=None): patternObject = re.compile(pattern) for line in source: ...
user1787812's user avatar
6 votes
2 answers
2k views

Does laziness yield more race conditions?

I recently ran into a race condition while accessing a configuration setting. After examining what I could of the code, I came to the conclusion that the Configuration class' laziness1 was the source ...
user avatar
6 votes
2 answers
454 views

Help me understand a part of Java Language Specification

I'm reading part 17.2.1 of Java language specification: http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.2.1 I won't copy a text, it's too long, but I would like to know, why for ...
dhblah's user avatar
  • 1,381
6 votes
2 answers
1k views

Erlang or 'x'.. Is it worth it (vs. Python w/ GIL)?

So, I've finally gotten myself to a point where I'm comfortable enough with Python (using Pyramid as my framework of choice) to undertake a rather large personal project. As it's a personal project, I ...
Demian Brecht's user avatar
6 votes
2 answers
886 views

Preemptive scheduling with "do not disturb"

In this answer about threading it is said: In preemptive scheduling, a thread can be interrupted at any time, either by a timer interrupt or any other interrupt or during a system call. The part of ...
user avatar
6 votes
1 answer
1k views

Why would CPython logging use a Lock for each handler rather than one Lock per Logger?

While developing my own logging library, I studied the source code of the standard logging module of CPython. One of its features is that handlers are thread-safe. One can write logs to a file from ...
Delgan's user avatar
  • 366
6 votes
3 answers
2k views

Design solution for communicating between multiple layers

We are developing a framework that has several layers and would be deployed in a multi-threaded environment. Each layer may have its own input/output data type. The top layer takes the input, performs ...
intoTHEwild's user avatar
6 votes
1 answer
7k views

What is a reasonable number of threads for a Java program?

In Java (or probably most other languages targeting the JVM) what is a reasonable number of threads to use? Presumably, this will be expressed as a ratio to the number of cores/processors available, ...
3Dave's user avatar
  • 509
6 votes
2 answers
3k views

Pthread scheduling (System and Process)

I've read the operating system concepts 8th edition written by abraham silberschatz. However, I don't understand Pthread Scheduling. Thread-library schedules user-level-threads on LWP(Lightweight ...
Danny_Kim's user avatar
  • 241
6 votes
1 answer
4k views

When should I use ZeroMQ and when should I use Akka?

My understanding of Akka is that it allows you to define groups of mini-threads ("Actors") and then have them communicate with each other (and do work) using events. My understanding of ZeroMQ is ...
herpylderp's user avatar
  • 2,027
6 votes
1 answer
3k views

Best Creational Pattern for loggers in a multi-threaded system?

This is a follow up question on my past questions : Concurrency pattern of logger in multithreaded application As suggested by others, I am putting this question separately. As the learning from ...
Dipan Mehta's user avatar
  • 10.6k
6 votes
1 answer
390 views

Threading models when talking to hardware devices

When writing an interface to hardware over a communication bus, communications timing can sometimes be critical to the operation of a device. As such, it is common for developers to spin up new ...
Fuzz's user avatar
  • 385
6 votes
2 answers
2k views

Thread class design?

I have a method like this in my UI code: void MyDialog::OnCommandSaveData() { std::list<MyClass*> objects; service_->GetAll(objects); dataService_->SaveObjects(objects); ...
User's user avatar
  • 1,551
6 votes
1 answer
358 views

Need to re-build an application - how?

For our main system, we have a small monitor application that sits outside our network and periodically tries to log in to verify the system still works. We have a problem with the monitor though in ...
Tom A's user avatar
  • 392

1 2
3
4 5
14