multithreading

concurrent queue in C++

I am trying to design a queue which could be simultaneously accessed by multiple read/write threads. I prefer using 2 mutexes, one apiece for read and write. Doing write is simple enough, lock the write mutex, append data, unlock and you are done. The issue is with read. If there's no data in the in queue I'd like my thread to wait til...

The more threads that changes the Clojure's ref are, the more does the rate of retries per threads rise?

I worry about this a little. Imagine the simplest version controll way that programmers just copy all directory from the master repository and after changing a file do reversely if the master repository is still the same. If it has been changed by another, they must try again. When the number of programmers increases, it is natural tha...

Toast Immediately

I would like to have a Toast Message appear while my app is downloading information but even if I put it before my code it doesn't appear until after the download has completed. Putting my code in a separate thread causes many headaches but putting toast in a separate thread doesn't work either. Is there anyway I can have this Toast me...

Java uses object as monitor, isn't that object too heavy weight?

I read this in Java language Spec 17.1: "Each object in Java is associated with a monitor, which a thread can lock or unlock." Why necessarily? Doesn't that make java object too heavy weight? I've no idea why a Object like, say, a string, should be naturally a monitor! EDIT: I think it over and yes, Java has a keyword synchro...

How should I update a hash of hashes when using multi-threading in Perl?

I have been spending the last hours trying to figure this out and now I'm really confused. This is the outline of my task. I should write a Perl subroutine that gets a reference to a hash of hashes. I have another sub (helper) that gets a single inner hash and does some stuff to with, including adding keys. sub helper { $href = sh...

Which thread pool manager is recommended for Perl?

I only know of Thread::Pool which is apparently not supported in recent Perl versions, and Thread::Pool::Simple which lacks almost any documentation. So which thread pool manager can I use under Perl v5.10.1 or and higher? ...

How do I get the Exception that happens in Timer Elapsed event?

I'm working with Windows Forms application and hava a manager class that uses System.Timers.Timer to periodly check data from database. How do I get the Exception that occurs in timer Elapsed eventhandler delivered into main application? If I'm using the code below, the exception get's "swallowed", and main application never gets it (e...

One thread changes BOOL to YES, another thread doesn't see change

I have a property declared as the following: @property(assign) BOOL die; One thread continuously checks if it should die by looking to see if that variable has changed to YES. When that die is set to YES (by a user clicking a button), the other thread that is grinding away still sees it as NO. I've put careful traces through the code ...

Long PHP SOAP process

I've been working on a website that get all its data through SOAP. Some pages may have three or four calls to the soap server and some of the calls can sometimes take quite long (30-60 seconds). What I've noticed happening is if I interrupt the request during one of the long 30 second calls (stop the browser loading) and issue another ...

MPI column cyclic distribution of 2d array from root to other processes

Hi there, so like i wrote in the title, my problem is, that i have a C program which makes use of the mpi library. I initialised a dynmaic 2d array which dimensions(rows,columns) are read from the stdin at process root. So far so good no big deal. But when i try to distribute the elemnts columns cylic among the others im not making any...

ioctl and execution time

Hi, I have a program running two threads - they communicate using message queues. In one thread, I call ioctl() to access the hardware decryptor. The code goes like: void Decrypt { ... .. ... if(<condition 1>) {. ... ... retVal = ioctl(...); comesInHere1++; } if(<condition 2>) { ... ... retVal = ioctl(...); comesInHere2++; } come...

How do I avoid cross-thread violations in a Ruby extension?

I'm writing a C extension, providing an interface between Ruby and an asynchronous I/O library. When running the tests over my code, I frequently get errors including (but not limited to): [BUG] cross-thread violation in rb_thread_schedule() Asynchronous IO means my C extension will need to deliver messages to ruby from multiple threa...

ScheduledThreadPoolExecutor with one scheduled task(Runnable) keeps reporting back job counter + 1 all the time

I get an ever increasing(like 1,2,3,4,5,6,7...) task count when I print s.getTaskCount(). I don't understand why. public class MyTask implements Runnable { public void run() { System.out.println("whatever...."); } } ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(3); s.scheduleAtFixedRate(new MyTas...

Why does Rhino Mocks throws an Exception when using it with threads?

Hello, we have a weired problem when using Rhino Mocks and Threads. I've tried to isolate the problem, but now I'm stuck to this: [TestClass] public class FoolTests { [TestMethod] public void TestMethod_Scenario_Result() { for (int i = 0; i < 5; i++) { var fool = MockRepository.GenerateStub<IFool>(); ...

android startActivityForResult is killing a thread within the parent activity

Hi, I have an activity which has a thread and a view in it...they're suspiciously similar to LunarLander. To show an in-game menu, i'm calling the startActivityForResult for a different activity which has a number of buttons on it...this is then returning the button type pressed to the parent activity. This is fine except when I carry on...

Multithreaded repeater in Python

I have small repeater Below that keeps ending, How can fix so more stable from crashes, and not stop running.... I would I add a heartbeat to the gui to see that its still running. In Wxpthon, my menu bar goes blank or white. def TimerSetup(): import threading, time invl = 300 def dothis(): try: ...

Event Handling in Threading Architecture Issue

I am dealing a big situation in architecture design flaw in multiple threading. I try to keep my application completely thread safe and avoid conflict with each others. The problem I was aware was this: Assume there are two threads, Thread A and Thread B. Thread A is something that you'll see from Static Void Main method as the only t...

ASP.NET reset thread culture after use?

If I set Thread Culture and UICulture for one ASPX, after pass for that page, all my aspx that use the same thread(not same request) will have the same Culture? Because I need to set Culture just for one ASMX ...

Random numbers and thread local storage

The accepted answer to this question, and a similar discussion at work today got me to wondering about something. The question was about how to safely generate random numbers in a multi-threaded program. The accepted answer advocates using thread local storage, effectively creating one random number generator per thread. I wonder if t...

How many threads can I spawn before efficiency drops?

Is there any formula, maybe involving RAM & number of CPUs, which can give me a rough idea of how many threads I can spawn before it starts to be inefficient and slows the PC? I want to load test another machine, so want to send requests as quickly as pobbile. But there's no point of spawning a million threads if they will just get in e...