multithreading

Best practices: syncing between threads

Is if almost always required to have thread syncing (i.e. use of mutex, semaphores, critical sections, etc.) when there is cross-thread data accessing, even if it's not required after going through a requirements analysis? ...

Java synchronize statement around a lock

I was wondering if synchronize (lock) { ... } Where lock is an instance of java.util.concurrent.locks.Lock, treats lock like any other object or as the try-finally idiom i.e. lock.lock(); try { ... } finally { lock.unlock(); } ...

Can a slow network cause a Python app to use *more* CPU?

Let's say we have a system like this: ______ { application instances ---network--- (______) { application instances ---network--- | | requests ---> load balancer { application instances ---network--- | ...

Backgroundworker : exception during cancellation

I have a background worker wich can be cancelled. The normal flows interrupt itself when the CancelPending variable turns to true (responding to user interaction on UI wich call worker.CancelAsynch() ) , exceptions are thrown because if that (since normal flow is interrupted, lots of null ref exception are thrown) So when the worker r...

Implementing a thread-safe, generic stack in C++ on linux

Hi All, In a recent interview, I was asked to implement a thread safe generic (i.e.template based) stack in C++, on linux machine. I quickly came up with the following (It may have compilation errors). I got through. The interviewer probably liked something in this implementation. Maybe the design part :) Here are a few problems that th...

Detecting when an object is passed to a new thread in C++?

I have an object for which I'd like to track the number of threads that reference it. In general, when any method on the object is called I can check a thread local boolean value to determine whether the count has been updated for the current thread. But this doesn't help me if the user say, uses boost::bind to bind my object to a boost:...

Are tasks parallelized when executed via an ExecutorCompletionService ?

I submitted 5 jobs to an ExecutorCompletionService, but it seems like the jobs are executed in sequence. The ExecutorService that is passed to the constructor of ExecutorCompletionService is created using newCacheThreadPool form. Am I doing anything wrong ? UPDATE Each job is basically doing a database query & some calculation. The code...

Does read-only file system access guarantee a write access?

Hello, I am developing a web application and I am wondering if someone has a full read-only access to my filesystem, can this person (assuming that he is aware of everything necessary) have a write access to the system? For example, if you have a PHP script that outputs contents of any files on the server - will someone really be able ...

How do I asynchronously poll a file using a flash timer without blocking the UI?

I have a flex application that repeatedly polls a remote XML file to detect changes, but I've found that once the file hits a certain size, the poll blocks the UI and makes the page unresponsive for a short time. Is there any way to ensure that the call made to the server or the event from the flash.utils.Timer class runs asynchronousl...

Mutex in Python Twisted

I'm using the Twisted framework, and am getting RPCs asynchronously. I have another function which does a task every 2 seconds, and sleeps in between. This is called through reactor.callInThread. These depend on a shared resources, so I need some thread-safe way of accessing them. How does one go about using critical sections / mutexes /...

Killing a thread (C#)

Hello I have created a thread that has a method that's running. But sometimes I will want to kill the thread even if the method is still working. How can I do this? I tried Thread.Abort() but it seems to show up a messagebox saying "Thread aborted". How should I go about this? ...

Windows Service and Timers - Separate Processes?

What is the difference between having multiple Timers vs multiple Threads? I have a Windows service that runs in the background. There are about ten "Sites" in a database that get loaded on init. Each site gets initialized in its own Timer object, and then the Timer executes code on an interval for each site. The code executed is fro...

Thread specific memory with language features.

Are there languages that support process common memory in one address space and thread specific memory in another address space using language features rather than through a mechanism like function calls? process int x; thread int y; ...

A Unique and Constant Identifier for a pthreads thread?

I presumed that a pthread_t remains constant - for a given thread - for its entire life, but my experimentation seems to be proving this assumption false. If the id for a given thread does not remain constant across its life, how can I store a pthread_t so another thread can use pthread_join to block until the thread is finished? For ot...

Thread safe singleton implementation in C++

The following is a well known implementation of singleton pattern in C++. However, I'm not entirely sure whether its thread-safe. Based upon answers to similar question asked here previously, it seems it is thread safe. Is that so? //Curiously Recurring Template Pattern //Separates a class from its Singleton-ness (almost). #in...

Derived class for Ruby Thread?

I've lived in the C++ world for years, and I'm just starting out with Ruby. I have a class that I would like to make a thread. In Ruby is it wrong to derive a class from Thread? The examples I see use the concept below. Thread.new { <some block> } Would it be wrong to do this? class MyThread < Thread def initialize end def ...

using STAThread on ArcFM license

I am trying to use ArcFM with my ArcGIS project, and I've noticed a bug. If my main thread is marked with the [STAThread] attribute, the program hangs on exit with the OS Loader Lock exception. When I remove that attribute the program ends just fine. The following code hangs [STAThread] private static void Main() { MMAppInitialize m...

How do I abort, pause and resume threads in C#?

How do I abort, pause and resume threads in C#? Related question: Is there a way to indefinitely pause a thread? ...

Gracefully closing multithreading application?

I have an application that has two threads. The first one (the main thread) that captures the data using socket and update DataTables The second Inserts the DataTables into the database. The application works fine but when it closes, the main thread finishes reading the data and call Abort method in the second thread, which may be ins...

Restarting a thread in .NET (using C#)

Hello there, I'm looking for a way to restart a thread that has been stopped by Abort().. public partial class MyProgram : Form { private Thread MyThread = new Thread(MyFunction); private System.Windows.Forms.Button startStopBtn = new System.Windows.Forms.Button(); public MyProgram() { MyThread.Start(); startStopBtn += ...