multithreading

Resource stack that waits if empty, until an element is pushed

I want to build a stack of resources that will be used by different threads, but want to block to calling thread up to a timeout until a resource becomes available. The method WaitUntilTheStackHasMember() is the part I am lacking. I though of using a method like the one described on MSDN's timer and autoreset event, but it got complic...

Is a volatile reference a safe way to pass MotionEvents between threads?

I am curious about the safety of this method I have considered using for passing touch events in my Android application (and testing my understanding of concurrency in Java). Here's the basics: I have a SurfaceView hooked up to SurfaceHolder.Callback to get user input events, mainly the onTouchEvent callback. After the onTouchEvent met...

Thread.Abort doesn't seem to throw a ThreadAbortException because of AcceptSocket

I am calling ChannelServer.ListeningThread.Abort on the following thread, however nothing seems to happen. I would like to be more specific, but I can't think of anything more. There seems to be no ThreadAbortException that is thrown, and this exception should be thrown regardless of the blocking listener (it works perfectly on threads t...

CreateThread issue in c under window OS

I have the following code which initiate the thread. int iNMHandleThread = 1; HANDLE hNMHandle = 0; hNMHandle = CreateThread( NULL, 0, NMHandle, &iNMHandleThread, 0, NULL); if ( hNMHandle == NULL) ExitProcess(iNMHandleThread); My question is What will happened if I run this code while the thread already in the running state. I want ...

Cache with timeout using .Net 4 & Concurrent Collections

How would you implement a cache class that supports timeouts using the new Concurrent Collections of .Net 4? The cache class will be typically holding hundreds of thousands of entries. A very large part of the cache may expire simultaneously. Unlike a typical web cache, which may shrink due to memory pressure, this class should only a...

Designing multithread application (looking for design patterns)

I'm preparing to write a multithread network application. At the moment I'm wondering what's the best thread pattern for my program. Whole application will handle up to 1000 descriptors (local files, network connections on various protocols and additional descriptors for timers and signals handling). Application will be optimized for Lin...

Python limited multithreading

Hi all, As you surely know, I can do multithreading to download files from the Internet faster. But if I send lots of requests to the same website, I could be black listed. So could you help me to implement something like "I've got a list of urls. I want you to download all of these files but if 10 downloads are already running, wait ...

timer inside a thread

how to start a forms.timer inside a simple thread,i have a problem where i need to start a timer inside a thread,how can i do that ...

Which implementation is better: Cache based on WeakHashMap or cache based on ThreadLocal?

Hello, I'm having hard time to decide between the following two implementations. I want to cache the javax.xml.parsers.DocumentBuilder object, per thread. My main concern is runtime performance - Hench I would be happy to avoid as much GC as possible. Memory is not an issue. I've written two POC implementations, and would be happy to ...

Call to Java Object's wait() breaks thread synchronization

public class Main2 { public static void main(String[] args) { new Test2().start(); new Test2().start(); } } class Test2 extends Thread { @Override synchronized public void run() { try { System.out.println("begin wait"); wait(); } catch (Exception ex) { } ...

isAlive() method of java thread is not working properly?

I was trying a example of isAlive() method of java threading. But i found that isAlive() method is returning false even if thread has been already started. Can someone please tell me what am i doing wrong? Here is the code snippet. package app; public class ThreadAliveDemo { public static void main(String[] args) { Threa...

How to use Multithreading, locks, Socket Programming.

For last 48 hours, I have been trying to understand Multithreading and Socket Programming. I tried to implement socket programming and had success when not using multithreading. I am new to both of the topics and have raised 2-3 question on stack itself needing help on the same. After googling a lot I found an article that explains So...

How can a Thread return a value after finishing its job?

Let's say we have this simple example: public Example extends Thread{ String temp; public Example(){ } @Override public void run(){ . . . . temp = "a_value"; } public static void main(String[] args) { Example th = new Example(); th.start(); } } How can the T...

c# inter-thread communication

hello i want to threads to collaborate a producer and a consumer. the consumer is rather slow, and the producer is very fast and works in bursts. for example the consumer can process one message per 20 seconds, and the producer can produce 10 messages in one second, but does it about once in a long while so the consumer can catch up. ...

How Java program divided between CPUs (in multi CPUs systems)

I start Java my Java application on system with 16 CPUs, but mostly loads on first CPU. Is it normal? If not, how can I repair it? top - 18:40:52 up 42 days, 22:18, 2 users, load average: 8.36, 11.87, 15.61 Tasks: 214 total, 2 running, 212 sleeping, 0 stopped, 0 zombie Cpu0 : 42.3%us, 1.7%sy, 0.0%ni, 52.0%id, 0.0%wa, 0.0%h...

Question about lock objects and sub classes

Hello, So, I have a base class which has a private locking object like so: class A { private object mLock = new object(); public virtual void myMethod() { lock(mLock) { // CS } } } This locking object is used for most of A's operations... because they need to be thread safe. Now, ...

How can I log which thread called which function from which class and at what time throughout my whole project?

Hello, I am working on a fairly large project that runs on embedded systems. I would like to add the capability of logging which thread called which function from which class and at what time. E.g., here's what a typical line of the log file would look like: Time - Thread Name - Function Name - Class Name I know that I can do this by ...

Executing a python script using subprocess.Popen() in a django view

I've looked around a bit but I can't seem to solve this problem I have. I'd like to execute a python script within a view of my django app. I've placed the code I'd like to execute inside a django management command so it can be accessed via command line python manage.py command-name. I then tried to run this command using subprocess....

On a multicore x86, is a LOCK necessary as a prefix to XCHG?

If mem is a shared memory location, do I need: XCHG EAX,mem or: LOCK XCHG EAX,mem to do the exchange atomically? Googling this yields both yes and no answers. Does anyone know this definitively? ...

boost threads mutex array

hello. My problem is, I have block matrix updated by multiple threads. Multiple threads may be updating disjoint block at a time but in general there may be race conditions. right now matrix is locked using single lock. The question is, is it possible (and if it is, how?) to implement an efficient array of locks, so that only portions...