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

learn more… | top users | synonyms (5)

0
votes
1answer
109 views

How to let multiple threads write on the same file [closed]

I have got a text file called "vholders.txt". I am making multiple threads as you can see here ,those threads work with their own given data and at last they write their own output to the ...
0
votes
0answers
87 views

Java Multi-threading

I was solving this question in Java where the user enters a partitioned array. The computer then determines what all elements from that array can be used as pivots. (Pivots are the same pivots that ...
1
vote
1answer
25 views

ThreadPool.QueueUserWorkItem is this example a valid use case?

I need to send out a batch of reminder emails, never more than 100 emails per batch, using authenticated SMTP. This is happening on a WindowsService (no GUI). The SMTP library we're using raises a ...
1
vote
1answer
92 views

Does it make sense to have a user specified thread limit?

I'm developing a C++14 application and would like to take advantage of the new multithreading features, in particular std::async. I have seen a number of applications which allow the user to specify ...
0
votes
1answer
53 views

Create/destroy multiple threads for animations/light effects

I'm developing a program for the Razer Deathadder and Firefly, I am going to create new light effects for the Firefly. I'm doing this in C# with the Colore library. Now these light effects will be ...
0
votes
0answers
57 views

How to prevent parallel calls to model?

While there is some command running which calls methods on some model, how to prevent concurrent calls for critical places in that model? If multiple requests comes in then they should maintain their ...
3
votes
3answers
114 views

What is “Split Data Model”, mentioned in the book “Java Concurrency In Practice”?

I'm learning Java multithreading programming by the book "Java Concurrency In Practice". In chapter 9.4.2 Split Data Model, I read this: From the perspective of the GUI, the Swing table model ...
1
vote
1answer
36 views

Coordinating threads in a multithreaded server

The goal is to develop something similar with a quiz application: there is a server to which players connect. At some point, a game is started. The game consists in asking the players a few multiple ...
3
votes
6answers
169 views

OpenGL, multithreading, and throwing destructors

How do you make an class that properly warns a developer in the future that they've made a mistake somewhere in their implementation that resulted in an object that gets deconstructed in a state that ...
0
votes
2answers
44 views

Double-check locking around initialisation which performs a web request

I've just refactored some code that managed a global state cache of values that didn't have locking to use double check locking. Other than moving the initialisation to a single source (the cache was ...
6
votes
2answers
135 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 ...
6
votes
1answer
85 views

Python: Control subprocess from calling thread

I am working on a database interface to a MongoDB using Python Eve as an API. The database stores several documents containing parameters and values needed for some calculations. I wrote a Python ...
2
votes
2answers
119 views

Java Thread.sleep() considerations

I've been doing some testing in an app that I've been involved with for the past little while, and it appears as though some of the code we've written is causing a race condition. What's happening is ...
1
vote
2answers
113 views

Thread-safe events — locking on privately held references

I was reading about delegates and events on this webpage to get a better understanding of them and how they relate to each other. While reading, I came across this statement: That goes against ...
4
votes
2answers
279 views

What is it called when threads are waiting but not deadlocked

The definition of a deadlock is when two or more threads cannot complete their execution because they are mutually blocked and waiting for something from the other thread(s). Is there a similar term ...
1
vote
4answers
270 views

Why is dealing with multiple threads considered difficult? [duplicate]

You can say this is opinion based, but the problem is that everyone's opinion on this issue is same. Even the lead developers say that creating the threads is easy, dealing with them together is ...
10
votes
2answers
413 views

Why do programmers define programming models to replace C/POSIX for parallelism?

Providers of new computer architectures regularly try to introduce new programming models, e.g. recently CUDA/OpenCL for GPGPUs, and displace C/POSIX as the control interface to platform ...
3
votes
1answer
108 views

Minimizing lock time (multithreaded app)

I have a web application written in C# which uses external dll written in C++. Communication between clients (web browsers) and a web application is done using SignalR. For communication between web ...
1
vote
0answers
54 views

When do you need precision with thread execution timing and how do you do it with Java? [closed]

(Under software architecture/design) I'm not sure how my question could be subjective but the message next to the title suggests that it is. I hope I'm not violating the rules here. Under what ...
1
vote
0answers
29 views

Push instead of pull on a list that might change due to a command in addition to events? [closed]

I need to show a refreshable/searchable list of items and update/add-to it whenever an event is published. How do I make sure no events are lost while refreshing/searching is happening? Some sort of ...
1
vote
0answers
86 views

Running simulations in parallel, managing each separately [closed]

Let me preface this by admitting that I am a novice - this is the first real project I am doing outside of a class. I am running a single-threaded C++ simulation several hundred times (i.e. I have ...
-1
votes
1answer
66 views

Approaches to Concurrency [closed]

I’ve been doing some research on the various approaches to concurrency, and I’ve ended up with the following taxonomy: Manual thread based concurrency with locks Asynchronous dispatch queues and ...
5
votes
1answer
76 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 ...
4
votes
1answer
71 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 ...
2
votes
4answers
163 views

Is it a good idea to make method behavior depend on the calling thread?

I want to subclass a 3rd party class, in order to make it thread-safe. I have a good idea of how to implement this, but there is a problem: the superclass has a property, which affects the behaviour ...
1
vote
2answers
123 views

Don't quite understand check and set in concurrency

I don't entirely understand check and set behaviour.. here is an example: public static void main(String[] args) { List<String> list = Collections.synchronizedList(new ...
1
vote
0answers
63 views

Better choice of Queue then a ConcurrentLinkedQueue if I have low number of threads in Java

I have two threads, one that is reading messages from the web and putting them into some sort of a queue. The other is suppose to read it. I looked into a ConcurrentLinkedQueue and it looks good for ...
5
votes
1answer
113 views

How can I best test a multithreaded C producer-consumer program? [closed]

How does one best write tests for a multi-threaded producer-consumer C program? I know GDB can be used to debug threads, but I believe GDB also stops the thread currently being debugged while other ...
1
vote
0answers
68 views

Terminology - Difference between thread and process and how they manage DB connections

I've been working more with concurrency in Ruby recently, and I keep seeing various articles using "threads" and "process" interchangeably. What are the actual definitions of these terms? Is a ...
1
vote
0answers
40 views

Cost of cache coherency/sharing data across multiple cores?

If I have two CPU cores, one is writing a particular cache line and the other core wishes to Read Write the same cache line, what are the costs (in cycles) for doing so? I am a little unsure ...
3
votes
1answer
84 views

Eliminating thread affinity requirements when converting an STA COM object into an MTA COM object

Suppose I need to convert an STA COM object into an MTA object. Single threaded apartments guarantee not just that only one thread will call the object at a time, but that it's always the same thread ...
2
votes
1answer
998 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 ...
0
votes
2answers
160 views

What happens to lock's state and methods when a thread acquires a lock?

Assume I have following class class Student{ void method1(){ // Do Something } void method2(){ // Do Something } } And the object of this class is used as monitor in ...
35
votes
4answers
4k views

Why is it the caller's responsibility to ensure thread safety in GUI programming?

I have seen, in many places, that it is canonical wisdom1 that it is the responsibility of the caller to ensure you are on the UI thread when updating UI components (specifically, in Java Swing, that ...
8
votes
1answer
103 views

Do classes in a JRE library support observable and/or asynchronous reads from external/non-JRE assemblies?

How can I implement my cross-platform library (e.g. on JRE) to operate in a thread-safe manner on object references, so that native front-ends on other platforms can observe the object and take ...
0
votes
1answer
93 views

Thread synchronization for multiple threads accessing a message stream

My project has a single message stream (communicating with an external device) which is accessed via multiple client threads. The workflow is: There is a thread (the "messaging thread") which reads ...
4
votes
1answer
285 views

C# async/await: Pedantry vs. the Debugger

I'm playing around with async and await, and they seem pretty intuitive, but some of the things I'm reading about these keywords doesn't make sense to me. In fact, some of it seems to me to be ...
2
votes
1answer
134 views

Multithreading with triple buffer, do I have to do the waiting for the condition variable?

I have a triple buffer implementation that is often used in threads in such a way that when new data is expected, there's always a WaitData(n) function called on the buffer (A condition variable's ...
0
votes
1answer
209 views

Performance of sharing single object with multiple threads in Java

In Java, if I create an object that has a method to do something, and I pass that object to multiple threads which call the method, is there a performance difference from creating an individual ...
4
votes
2answers
64 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 ...
1
vote
0answers
120 views

Threading strategies for a webservice implementation

If I am building a webservice/Web API for servicing requests, there are 2 threading strategies I can think of. I will explain this in terms of Java (though the question may be relevant for any other ...
3
votes
1answer
282 views

How do I prevent a long running SQL query from looking stuck?

If I had a method like: private void someMethod() { runSqlQueryA(); runSqlQueryB(); runSqlQueryC(); } My understanding is this method will be one thread. In weblogic, the thread will ...
1
vote
1answer
229 views

Behaviour of Thread sleep in a single core processor machine?

I'm trying to understand how threading works when using a single core, not hyper-threaded processor. I have two identical console applications running on a machine that has one core CPU and 1 GB of ...
0
votes
2answers
88 views

Built-in the separate thread execution inside of the method or wrap the method by the thread

Let assume, I have some resource and time-consuming code, which I want to arrange as a separate method. In order to optimize the performance, this code should be executed in the separate thread. Now ...
3
votes
1answer
105 views

Design approach to outsourcing a socket in an own thread

I want to extend an existing server written in C++ to be able to communicate with an other server over websockets (e.g. logging or user authorisation purposes). All examples (including the very well ...
2
votes
1answer
81 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 ...
0
votes
2answers
183 views

What's the simplest way to deal with events in C in this situation?

I'm writing a text-based game, in C. I want the game to handle NPCs movement and actions in the background, while the user is making his moves. I'd also use time-based events to tell the user when ...
0
votes
2answers
114 views

Multiple threads making call to precompiled library

I have been asked this question in an interview and I thought to take advice from you guys. Say I have a pre-compiled library which references to some function say "strtok". There is no source code ...
0
votes
1answer
123 views

Android Service vs Simple class with thread for network access [duplicate]

I am in quite a dilemma about how to solve my problem regarding network access. I checked this question but it does not really gives a solution for my problem. All of my REST based requests are ...
4
votes
2answers
625 views

How many threads is too many to maintain a chat server?

I'm writing a chat server and client. For the chat server I have 3 "services" all running on their own threads: ConnectionListener that loops over accept, and adds any new clients to a ...