multithreading

Java: How to do double-checked-locking with an array element?

This is what my code currently looks like: private boolean[] isInitialized = new boolean[COUNT]; private void ensureInitialized(int i) { if (! isInitialized[i]) { initialize(i); isInitialized[i] = true; } } Now I want to have it thread-safe. I know that double-checked-locking in Java is "teh 3vilness!!1", but ...

Parallel JavaScript Code

Is it possible to run JavaScript code in parallel in the browser? I'm willing to sacrifice some browser support (IE, Opera, anything else) to gain some edge here. ...

How does Android handle background threads when leaving an Activity?

I need my Android app to save it's state to disk when its activity is put in the background or killed. It's been suggested that I start a thread when onPause() is called and perform any expensive I/O procedures there (see http://stackoverflow.com/questions/3894668/saving-loading-document-state-quickly-and-robustly-for-image-editor). In ...

Does python's fcntl.flock function provide thread level locking of file access?

Python's fcnt module provides a method called [flock][1] to proved file locking. It's description reads: Perform the lock operation op on file descriptor fd (file objects providing a fileno() method are accepted as well). See the Unix manual flock(2) for details. (On some systems, this function is emulated using fcntl().)fu...

Lambda expressions, captured variables and threading

I know that .NET lambda expressions can capture outer variables. However, I have seen it a lot of times that variables are passed explicitly to the lambda expression as a parameter, and the .NET library also seems to support that (e.g. ThreadPool.QueueUserWorkItem). My question is that what are the limitations of these captures? How abo...

C# HTTPWebRequest Multi-threading

Hi all, I am new to threading. I am trying to send HTTP Web Request using multi threading, I am not able to acheive what I need. My requirement is to send request to thousands of same or different websites and parse the response i get it from httpwebrequest. In the below code, i am sending 2 simulteaneous threads, I am looking for ten...

Visual Studio, debug one of multiple threads

I have an application with 4 threads working the same code. However, when I step it jumps between the different threads. How can I lock it to one thread so the other threads are ignored for debugging? ...

Why thread is interrupted before the changes are complete.

I'm attempting to create python module for getting MAC adresses by IP addresses. def getMACs(addressesList): def _processArp(pkt): spa = _inet_ntoa(pkt.spa) if pkt.op == dpkt.arp.ARP_OP_REPLY and spa in _cache.macTable: lock.acquire() try: _cache.macTable[spa] = _packedToMacSt...

Non-blocking native files access - single-threaded daemon in C?

I've found out that native files access has no "non-blocking" state. (I'm correct?) I've been googling for daemons which are "non-blocking", and I've found one which achieved said behavior by threading file access operations, so that the daemon won't block. My question is, wouldn't threading and IPC'ing such operations be rather expens...

thread contention on dynamic memory allocation

Hi All I have just learnt that in C language malloc function comes with the issue of thread contention when used in a multi-threaded applications. In C++ does operator new suffer from the same problem? If yes what tecnhique can I use to avoid this that sounds like a big penalty in the application performance? Thaks AFG ...

Python, is it proper for one thread to spawn another

I am writing an update application in Python 2.x. I have one thread (ticket_server) sitting on a database (CouchDB) url in longpoll mode. Update requests are dumped into this database from an outside application. When a change comes, ticket_server triggers a worker thread (update_manager). The heavy lifting is done in this update_manager...

wait() and notify() method , always IllegalMonitorStateException is happen and tell me current Thread is not Owner Why?

package pkg_1; public class ExpOnWaitMethod extends Thread { static Double x = new Double(20); public static void main(String[] args) { ExpOnWaitMethod T1 = new ExpOnWaitMethod(); ExpOnWaitMethod T2 = new ExpOnWaitMethod(); T1.start(); T2.start(); } public void run() { Mag...

Can you make sure all threads are started with a specific culture?

In my windows service, Spring.NET creates some threads handling jobs. Is it possible to make sure all these threads are started with a specific culture? Or do I have to set the culture in each thread? In ASP.NET, you can set the culture (globalization tag in web.config) at application level... can this be done in Windows Forms/Windows S...

the dialog desn't show correctly when it's created in sub-thread

I'm trying to add a pop-up message function in my project.And I make it run in a subthread since I need a realtime notification.But I find if the notification dialog is created in my subthread(started by AfxBeginThread),all the elements(buttons,urls....) of the dialog are not shown.The message box is just a blank dialog.If I extract the ...

Which blocking threading operations in .NET will handle COM messages when blocked?

When creating a new STA thread to host an STA COM component, it is the responsibility of that thread to pump Windows messages related to COM. From what I've been able to gather, certain built in .NET threading primitives such as lock (Monitor.Enter) will do this for you while waiting for the object to be released by another thread. Anoth...

Python hangs in futex calls

I have a Python daemon running in production. It employs between 7 and 120 threads. Recently the smallest instance (7 threads) started to show hangs while all other instances never showed this kind of problem. Attaching strace to the python process shows that all threads are calling futex FUTEX_WAIT_PRIVATE, so they are probably trying t...

Returning an iterator in a multi threaded environment, a good idea?

Is it a good idea to return an iterator on a list in an object that is used and shared in a multi threaded environment? class RequestList { public: RequestList::RequestList(); RequestList::~RequestList(); std::list<boost::shared_ptr<Request> >::iterator GetIterator(); int ListSize(); void AddItem(boost::shared_ptr<R...

wait and notify problem

When I am using the wait() method in the following code its throwing the following Exeption Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException The code is as follows: private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) { newFileChoo...

Updating a NSTableView data source from a background thread.

What is the best way to synchronize a data source which is updated frequently from a background thread with the GUI main thread? Should i put a pthread mutex around each method call? This seems to be pretty heavy too me. EDIT: I'm looking for a 10.5 solution ...

WPF threading for monitoring Process.Start and showing progress bar

Hello: I am trying to execute a Process.Start() that is a long running process, and show a circular progress bar on the screen while the process is executing. I have the following lines of code: Process p = Process.Start(longRunningProcess); // show the circular progress bar; ShowHideCirProgBar(true); // wait till the p...