multithreading

Locking file across services

What is the best way to share a file between two "writer" services in the same application? Edit: Sorry I should have given more details I guess. I have a Service that saves entries into a buffer. When the buffer gets full it writes all the entries to the file (and so on). Another Service running will come at some point and read the fi...

Sending data through a socket from another thread does not work in Python

This is my 'game server'. It's nothing serious, I thought this was a nice way of learning a few things about python and sockets. First the server class initialized the server. Then, when someone connects, we create a client thread. In this thread we continually listen on our socket. Once a certain command comes in (I12345001001, for ex...

Does a thread safe timer exist?

Is there another equivalent of Timer for android which is thread safe? Using the timer causes problems in my application while updating the gui, most of the time it complains that gui is being updated from another thread, i tried using handlers but that didn't fix the problem. ...

Safely Closing A Thread

I'm writing a bit of code that will open a MessageBox on a separate thread to prevent the MessageBox from stopping the program. It is very very important that starting a new thread will not crash the program that I am running, but I don't know enough about threads to make sure this happens. My question is, after starting the thread, h...

Must drawInRect: for a separate context be executed on the main thread?

[update: this problem has been resolved; the issue was not in drawInRect: but in UIGraphicsBeginImageContext()] In my app, I'm grabbing a bunch of large images, cropping them down to thumbnail size and storing the thumbnails for previewing. Note that I'm doing this in a separate image context -- this is not about redrawing a UIView th...

Does ruby have the Java equivalent of synchronize keyword?

Does ruby have the Java equivalent of synchronize keyword? I am using 1.9.1 and I don't quite see an elegant way to do this. ...

Download Email Attachments via Simulataneous Cron Jobs -- Race Condition

I need a cron job to check email accounts and download certain attachments. This cron job will be running every minute. My problem is that when the first script is downloading email attachments, a second (or third or fourth ...) script will most likley be running alongside the previously executed script. The problem is that I am not sure...

What does "AsyncTimerCallbackCompletion TimerInfo@" in !threadpool output mean?

Hello, Sometimes my application consumes 100 cpu. When I investigate crush dumps in windbg I always see huge "request queue" in the log and I am very suspicious of this huge amount of requests. Definitely I want to know where they come from, but at the first place I don't quite understand what it means. Does it mean that there are lots ...

Delphi - What happens with un-freed (but terminated) thread when application exits?

Hello, I have multithreaded application and I've got a little problem when application ends: I can correctly terminate the thread by calling TThread.Terminate method in Form1.OnDestroy event handler, but the termination does take some time and so I can't free the memory (by TThread.Free method). Unfortunately for some other reason I mus...

How to implement an Exchanger (Rendezvous Pattern) in C++?

In Java, there is an Exchanger class (http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Exchanger.html). How to implement something like that in C++ (using boost) ...

program of single thread with timer in java

hi any simple program for single thread with timer in java. that thread will run with particular time. i am new to this thread. thanks in advance ...

How it works? Google app engine + Spring

Hi, I wonder how spring and google app engine work together I know that google app engine cannot run threads. I think spring is wroking with threads. (if i'm wrong, please correct) So how spring and google app engine work together. ...

Stopping a Thread

Here is the situation. I have a thread that gets started with the click of a button. It then works for approx 2 min (give or take quite a bit) and then finishes, updating the UI and all along the way. It is quite nice. Now I have decided to add a "Cancel" button to the mix. My question would be what is the best approach to stop a th...

Can notifyAll() block?

EDIT: THE ANSWER IS NO! It just looks like it if you do this in a while loop. My fault. Hi! I have written a program that blocks in notifyAll() although it is out of my understanding why this is happening. Part of the stack trace is: "Client" prio=6 tid=0x03768c00 nid=0x8c4 runnable [0x0565f000] java.lang.Thread.State: RUNNABLE ...

How should I share and store data in a small multithreaded python application?

Hi all, I'm writing a small multithreaded client-side python application that contains a small webserver (only serves page to the localhost) and a daemon. The webserver loads and puts data into a persistent "datastore", and the daemon processes this data, modifies it and adds some more. It should also takes care of the synchronization w...

What is the most efficient way to make this code thread safe?

Some C++ library I'm working on features a simple tracing mechanism which can be activated to generate log files showing which functions were called and what arguments were passed. It basically boils down to a TRACE macro being spilled all over the source of the library, and the macro expands to something like this: typedef void(*TraceP...

How to handle thread exceptions in main thread, block all workers and notify them upon finishing?

I have a windows service doing some repetitive work (wcf calls) after logging programmaticaly at a web server. All calls are invoked through various threads running dependently in parallel, but if for example, the connectivity is lost, or the iis recycles, hence the inproc session management directs me to re-login, I want to handle this ...

Threads vs Cores

Hi all, Say if I have a processor like this which says # cores = 4, # threads = 4 and without Hyper-threading support. Does that mean I can run 4 simultaneous program/process (since a core is capable of running only one thread)? Or does that mean I can run 4 x 4 = 16 program/process simultaneously? My guess is the first one. From my dig...

why does my pygtk application crash when copying text on a clipboard?

Hi all, I'm writing a python application using pygtk. I have a main thread who occasionally calls another thread that is supposed to build a string and then copy it on the clipboard before dying. My "slave" thread looks pretty much like this: class Slave(threading.Thread): def run(self): s = build_string() c = gtk.Cl...

Instrumentation of method calls in a web app using PostSharp

Example: I add a PostSharp attribute to a method to ensure a stopwatch is started before the method is called, and stopped just after the call returns. This method is used in a web app, so it will be called by multiple threads. I store the result of the stopwatch timing in a static threadsafe collection, for use by all threads. This c...