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

learn more… | top users | synonyms (3)

6
votes
1answer
1k views

Sleeping Barber Problem (with multiple barbers)

The Sleeping Barber Problem is a classical synchronization problem that many of you may be familiar with or at least heard of. It's based on the premise that a barber (a thread) sleeps when there ...
0
votes
2answers
526 views

Memory allocation of Classes that don't have any global data and locks

static void Main(string[] args) { var c2 = new Class2(); var c3 = new Class3(); var c1 = new Class1(c2, c3); c1.Method1(); } class Class1 { ...
-2
votes
2answers
198 views

When will be safe to choose Multi-thread design without dead lock? [closed]

Sometime we really need to choose a multi-threaded design, because single-threading will block the UI or block another thread. But sometimes using multiple threads is just one of the choices, for ...
1
vote
2answers
191 views

What are the different aspects to consider when porting code from a single threaded environment to a multi threaded environment or vice versa?

I want to provide some library functionality and a reference application, which will run on a fully-featured, POSIX-compliant platform. The app and library will need bi-directional serial port ...
3
votes
1answer
103 views

Are mutexes assigned to specific regions of memory?

I'm currently reading C++ Concurrency in Action by Anthony Williams and I'm facing an obstacle in thought. First he describes deadlocks as when two threads lock simultaneously (at least, that's how I ...
4
votes
1answer
611 views

Design patterns for multi-threaded messaging server

I'm designing an instant messaging server as a personal exercise to improve my understanding and application of multi-threading and design patterns in Java. I'm still designing, there's no code yet. ...
2
votes
1answer
359 views

Python multithreading and utilizing modern processors - what is the downside?

CPython implementation detail: In CPython, due to the Global Interpreter Lock, only one thread can execute Python code at once (even though certain performance-oriented libraries might overcome ...
1
vote
2answers
118 views

Listener, logger, plotter - what threading arcitecture to choose for this?

I am constructing a program that does several things. Listens to a port. Every second a string is received When new data is received, it has to be logged. No errors or skipped entries are allowed ...
3
votes
5answers
337 views

What are some good assignments for an introductory course on concurrent programming? [closed]

I am teaching a course which involves introducing the students to the concept of threads and concurrent programming. I am in search of programming assignments that can gently get them to accept the ...
2
votes
2answers
227 views

How do I get rid of cyclic references in this design?

I have 3 classes: Meeting, Project and Agenda. A Project contains all sort of information + a list of meetings. The Agenda contains a list of upcoming Meetings. A Meeting contains some data + a list ...
2
votes
1answer
214 views

Multi-Thread Return Single SQL Result

I am having some difficulty with MySQL and returning a unique row to a thread. I want it so the thread will search for a row from the table where the bit (see below) is false and only one row is ...
1
vote
1answer
179 views

How do I find a good middle way to make this library safe for concurrent operations

I've made a little library called SignalR.EventAggregatorProxy Before I push it into 1.0 state I need to fix so it works safely with concurrent operations. Easiest way is lock all operations but ...
1
vote
1answer
493 views

Which child process will inherit threads of parent process?

What happens when one process have child threads and child process , will child process inherit all child threads of parent process.? Assume OS is Linux . Let it be Java Threading model.
3
votes
4answers
804 views

Should multi-threading be used for tasks which does not involve IO operation?

I was reading a book on OS and got confused between different terminologies. I hope i will get my doubt cleared here. These questions might be very basic for some experts, but i find this platform ...
1
vote
1answer
1k views

How to make a method synchronized across all instances of an object

Today I was asked this interview question and could not answer. : If you have two instances of a Person Object and each of them have a setAddres method that is synchronized. Now if it was only one ...
6
votes
3answers
1k 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 ...
9
votes
2answers
671 views

Uses of persistent data structures in non-functional languages

Languages that are purely functional or near-purely functional benefit from persistent data structures because they are immutable and fit well with the stateless style of functional programming. But ...
-1
votes
1answer
204 views

What operating systems use both a Render thread and a UI thread?

Microsoft employees commonly describe Windows 8 as having both a Render thread and UI thread. Typically they say the Render thread performs animations and the UI thread handles most other operations: ...
6
votes
2answers
4k views

How is multi-threading different in a Java based Web Application vs Stand-alone Java Application

I am fairly new to Java and my experience is limited to Web Based Applications running on a Web Container (Jboss in my case). Am I correct in saying that for Web Applications the web container takes ...
1
vote
1answer
2k views

High-Load Java Server for Multiplayer

I am making a multiplayer game. Now I am trying to choose the technology to connect the android devices to the server. The clients run on Android, and the game is MMORPG. I would like to write the ...
0
votes
2answers
128 views

Loading chunks around center

I am making a voxel game like Minecraft. I am able to load chunks using multithreading with the code... for (int x = 0; x < WorldSettings.WORLD_WIDTH_IN_CHUNKS; x++) { for (int y = 0; y < ...
1
vote
1answer
227 views

Is there a time bomb in sequential process id allocation when the `unsigned` wraps?

I'm designing and implementing a multiprocessing postscript interpreter ("lightweight" processes simulated by a single OS-thread), and I need to generate a unique identifier for each process in the ...
6
votes
4answers
561 views

Is it a performance hit to create threads that loop a lot to check for things?

This is a generic question that I've always wondered. In general, is it intensive for a CPU to create threads that perform "while not true ..." loops or similar? For example, suppose I do: // ...
8
votes
2answers
648 views

Would Task-based programming in C++ require new language standard features?

So I saw this video on Youtube with all these C++ masters on GoingNative 2012 : Interactive panel where everybody could ask the questions. This is the video I was talking about: GoingNative 2012 - ...
6
votes
4answers
2k 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 ...
0
votes
2answers
438 views

Multi-Threaded JavaScript?

I know, I know--it isn't possible presently BUT my question is this: Would it be possible to write a browser plug in for the major browsers that enables true, multi-threaded JavaScript? It just ...
26
votes
5answers
2k views

Testing multi-threaded race conditions

Reading the comments to this answer, specifically: Just because you can't write a test doesn't mean it's not broken. Undefined behaviour which usually happens to work as expected (C and C++ are ...
2
votes
2answers
305 views

Send stdout or stderr to a new thread

For performance issue I want the logging send to a new thread. While the main program can work, the new thread can write the error or other messages to a file without effect to the main program. How ...
0
votes
1answer
2k views

Android game loop in separate thread

I am about to port a game that was initially written for iOs and I am having some doubts how certain things should be done. I have been looking many of the examples of the game loops for android, and ...
13
votes
1answer
790 views

Best practise is not to poll…but isn't polling happening internally anyway when a thread calls wait()?

Say we have some thread that wants to check when another thread is finished its task. I have read that we should call a wait() type function that will make this thread wait until it receives a ...
0
votes
1answer
395 views

Multi-threaded server

I have written a server/client program in which I am using 2 threads : One to recieve data continously and Other to send data as the user writes it on screen Problem: I have created the threads ...
-2
votes
2answers
148 views

Calling blocking functions and execute code when result is ready, but without callbacks

I am designing an application that has some scripting capabilities: the host application may call the scripts to perform some operations when some events occur. To keep it easy and newbie-friendly, ...
7
votes
2answers
327 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 ...
2
votes
3answers
189 views

Is there a way to calculate whether to spawn a new thread or use current thread

I am building an interpret DSL in which parallelism is part of the language - the user simply states that a calculation can be done in parallel and the interpreter may decide whether to make the ...
1
vote
0answers
98 views

Thread safety IDE warnings

I wonder, would it not be possible for an IDE to detect any shared mutable objects that are used in multiple threads? You could flag types as either [ThreadSafe] or [Immutable] using attributes in ...
4
votes
2answers
417 views

Allow threads (in c) to print messages without interfering with user input

I'm a writing a small webserver for personal use in c (not c++). I want to allow user input in the console like "shutdown server" or "restart server". In order to allow this kind of input the server ...
8
votes
3answers
4k views

BackgroundWorker vs. Async/Await

I am new to C# development and wish to create a more responsive UI. In my preliminary research, I have seen two methods for achieving this: Multi-threading in conjunction with the BackgroundWorker ...
2
votes
2answers
187 views

Should I split out synchronization from my class and what's it called?

When thinking about testability and modular code, I recently thought about whether I should split out the synchronization part of a class from the actual behavior part. By example: The app "needs" ...
2
votes
1answer
498 views

Spurious wakeups explanation sounds like a bug that just isn't worth fixing, is that right?

According to the Wikipedia article on Spurious Wakeups "a thread might be awoken from its waiting state even though no thread signaled the condition variable". While I've know about this ...
25
votes
8answers
2k views

When would you need “hundreds of thousands” of threads?

Erlang, Go, and Rust all claim in one way or another that they support concurrent programming with cheap "threads"/coroutines. The Go FAQ states: It is practical to create hundreds of thousands ...
2
votes
2answers
3k 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 ...
4
votes
2answers
349 views

What is a good script language for writing server administration tasks? [closed]

I am administering hundreds of RHEL servers. There are many daily tasks to perform. Right now I am working with bash scripting and python. I was wondering if other languages such as Erlang, Lua, Ruby, ...
1
vote
2answers
616 views

How to preserve order of incoming requests on a multithreaded server

I want to write a multithreaded server application which is able to process requests in a multithreaded fashion while keeping up execution order of incoming requests of the same client. For example ...
2
votes
2answers
2k views

Can multiple CPU's / cores access the same RAM simutaneously?

This is what I guess would happen: If two cores tried to access the same address in RAM, one would have to wait for the other to access the RAM. The second time that each core would try to access ...
1
vote
2answers
838 views

Multitasking in C#

I would like to use a timer in my C# program with millisecond accuracy to keep a camera in sync with some events and keep shooting a picture every 250ms (or 1/4 sec, or I might adjust it to even ...
-1
votes
2answers
890 views

Difference between daemon and child thread?

As per my knowledge daemon thread is a thread that runs in background(low priority thread) and also a child thread runs in the background when the parent thread runs foreground so where does the ...
-2
votes
1answer
281 views

Why notify and wait are not declared in threads?

wait and notify are said to be communication mechanism in threads but then why are they not declared in Thread class and are declared in Object class instead?
5
votes
1answer
790 views

Many Blocking VS Single Non-Blocking Workers

Assume there is an HTTP server which accepts connections and then it has somehow wait for headers to be fully sent in. I wonder what is the most common way of implementing it and what are the rest ...
3
votes
1answer
5k views

How to program thread allocation on multicore processors?

I would like to experiment with threads on a multi-core processor, e.g. to create a program that uses two different threads that are executed by two different processor cores. However, it is not ...
15
votes
3answers
4k views

Why is multithreading often preferred for improving performance?

I have a question, it's about why programmers seems to love concurrency and multi-threaded programs in general. I'm considering 2 main approaches here: an async approach basically based on signals, ...