multithreading

Thread-safe C++ stack

I'm new to C++ and am writing a multi-threaded app whereby different writers will be pushing objects onto a stack and readers pulling them off the stack (or at least pushing the pointer to an object).. Are there any structures built-into C++ which can handle this without adding locking code etc.? If not, what about the Boost libraries? ...

How should I handle Multi-threading in Java?

I am working on a practical scenario related with Java;a socket program. The existing system and the expected system are as follows. Existing System - The system checks that a certain condition is satisfied. If so It will create some message to be sent and put it into a queue. The queue processor is a separate thread. It periodically ...

Should I unit test for multithreading problems before writing any lock? (.NET C# TDD)

I am writing a class that I know that needs a lock, because the class must be thread safe. But as I am Test-Driven-Developing I know that I can't write a line of code before creating a test for it. And I find very difficult to do since the tests will get very complex in the end. What do you usually do in those cases? There is any tool to...

java thread terminating early and suspiciously

I have the following code in a Runnable that gets passed to a thread t: public void run() { logger.debug("Starting thread " + Thread.currentThread()); try { doStuff(); } catch (Exception e) { logger.debug("Exception in Thread " + Thread.currentThread()); } logger.debug("End...

Background Thread for a Tomcat servlet app

I am not very familiar with Tomcat, in my head it is basically abstracted as a cgi server that saves the JVM between calls -- I know it can do a lot more than that, though. I am looking for a way to launch a background thread when a Tomcat server starts, which would periodically update the Server Context (in my particular case this is ...

C# Threading and Queues

This isn't about the different methods I could or should be using to utilize the queues in the best manner, rather something I have seen happening that makes no sense to me. void Runner() { // member variable queue = Queue.Synchronized(new Queue()); while (true) { if (0 < queue.Count) { queue.Dequeue(); } } } This is run in...

Is this class threadsafe?

Is this ValueStore class threadsafe? Does the lock scope in GetInt(string key) need to be extended around the yield return? public class ValueStore { private readonly object _locker = new object(); private readonly Dictionary<string, int> _data = new Dictionary<string, int>(); public ValueStore(Dictionary<string, int> data) ...

POSIX threads experience? (Or recommend better one)

I am looking for lightweight multi-threading framework for C++. I found POSIX Threads. Please, share you practical experience with POSIX threads: before I start with it I want to know its pros and cons from real people, not from wiki. If you practically compared it with anything (maybe, better), it would be interesting to know either. ...

MySQL Race Conditions

Does this cause a race condition with MySQL (InnoDB): Start Transaction. Try to get record. If record doesn't exist, return. If record exists, delete it and add a log entry saying that is was deleted. End Transaction (commit/rollback). Is it possible for another process to start just before the delete step in 2b, detect the presence ...

Is there an easy way to tell how much time is spent waiting for the Python GIL?

I have a long-running Python service and I'd like to know how much cumulative wall clock time has been spent by any runnable threads (i.e., threads that weren't blocked for some other reason) waiting for the GIL. Is there an easy way to do this? E.g., perhaps I could periodically dump some counter to its log file. My underlying motiva...

C# How do I prevent a TcpClient object from disposing in a different thread i've created with the new keyword?

So I'm trying to make a client for my server in C#, that accepts messages as commands so I can control the client remotely. I've had problem after problem with my masterServer.Connect taking FOREVER to load, and almost every time I close my application I have to wait 10 seconds for it to completely stop. I've tried EVERYTHING to stop thi...

Thread queues for dummies...

I have what I assume is a pretty common threading scenario: I have 100 identical jobs to complete All jobs are independent of each other I want to process a maximum of 15 jobs at a time As each job completes, a new job will be started until all jobs have been completed If you assume that each job will fire an event when he completes ...

Reducing the amount of threads in a .NET application

I have a medium-sized process viewer which uses around ~40MB of private memory on Windows Vista. The problem is that people always compare this number to the amount of memory used by Process Explorer and similar, unmanaged tools. I've noticed that when my program is idle, there are 13 running threads: One RPC thread (RPCRT4.dll!Thread...

Threaded implementation of observer pattern - C++

I'm developing a C++ program which has a "scan" method which will trigger a relatively long running scanning procedure. When the procedure is completed, the scan method will notify observers of results using the observer pattern. I would like to create a separate thread for each scan. This way I can run multiple scans simultaneously. W...

How to create a boost thread with data?

I'm running into some issues with boost::bind and creating threads. Essentially, I would like to call a "scan" function on a "Scanner" object, using bind. Something like this: Scanner scanner; int id_to_scan = 1; boost::thread thr1(boost::bind(&scanner::scan)); However, I'm getting tripped up on syntax. How do I pass the ...

What is the difference between a thread and a fiber?

What is the difference between a thread and a fiber? I've heard of fibers from ruby and I've read heard they're available in other languages, could somebody explain to me in simple terms what is the difference between a thread and a fiber. ...

Synchronous calculation-heavy method call that doesn't prevent redrawing

Newbie C#/.NET threading question here: Is it possible to have a synchronous (if that's the right term) method that doesn't return until it has finished some calculation but at the same time doesn't prevent the app from getting redrawn or going to "Not responding". I guess the answer is probably threads but how does one make them part ...

.Net CF Running Thread for lifetime of an application

Hello, I am developing a .Net Compact framework application in C# which utilises some third party message queuing software installed on the device. I am fairly new to this environment and was wondering if I could run a few key concepts of the architecture past some wiser eyes to see if I am on the right track or how it could be improved...

How to make two python programs interact?

I have a HTTP sever in one program and my basic application in another one. Both of them are loops, so I have no idea how to: Write a script that would start the app and then the HTTP server; Make these programs exchange data in operation. How are these things usually done? I would really appriciate Python solutions because my script...

How do I customize all the names of the child threads of a ThreadFactory in Java?

If I am extending an existing ThreadFactory implementation, how would I go able ensuring that all threads created would have the same prefix? I'm sick and tired of looking at Thread-9 in my logs and would like to distinguish between threads more easily. Does anyone have any suggestions as to how to go about this? ...