multithreading

C# Implicitly pass custom SecurityPrincipal to threads

Is it possible to pass a customer SecurityPrincipal reference on a main thread to other child threads? Is there any way to pass value-type information to the various threads via a context of some kind? This is running in a WCF environment where I want to run parallel code but find myself constantly resetting security information on eac...

Removing an item from a collection after some timeout

I want is to remove a Notification from a ObservableCollection<Notification> after some timeout. Is there a better way than starting a new ThreadPool thread for each added item and Thread.Sleep in there? Final code based on Nidonocu's answer: public class NotificationCollection : ObservableCollection<Notification> { private reado...

confused about spin lock

I read spin lock code from here, especially this part inline void Enter(void) { int prev_s; do { prev_s = TestAndSet(&m_s, 0); if (m_s == 0 && prev_s == 1) { break; } // reluinquish current timeslice (can only // be used when OS available and // we do NOT wa...

How do I do dynamic data transfer and memory management across threads in C?

Platform: ARM9 Programming Language C Requirements - plain C and no external libs and no boost. OS - REX RTOS I have two threads running in an embedded platform - one is at driver level handling all the comms and data transfer with the hardware. the second thread runs the application that uses the data to/from the hardware. Th...

A reasonable use of threading in C#?

As part of a large automation process, we are calling a third-party API that does some work calling services on another machine. We discovered recently that every so often when the other machine is unavailable, the API call will spin away sometimes up to 40 minutes while attempting to connect to the remote server. The API we're using...

Static Property and lock Usage

Is this code correct or is there any possibility of some random threading deadlocks etc? Is it a good idea to use static properties and locking together? Or is static property thread-safe anyway? Private Shared _CompiledRegExes As List(Of Regex) Private Shared Regexes() As String = {"test1.Regex", "test2.Regex"} Private Shared RegExSet...

C#: poor performance with multithreading with heavy I/O

Hi, I've written an application in C# that moves jpgs from one set of directories to another set of directories concurrently (one thread per fixed subdirectory). The code looks something like this: string destination = ""; DirectoryInfo dir = new DirectoryInfo(""); DirectoryInfo subDirs = dir.GetDirectories(); ...

Problem selecting class using jquery

Hi everyone, I've been banging my head against a wall trying make this work for a while now. I'm trying to shorten the comment body to one line for compact comment preview. I'm using jquery .each function to go through each .cbody (comment body) in my threaded comment system and place it in the cshort div inside chead. It should work but...

Running RESTful service in its own thread: how to start and stop the thread appropriately?

Hi, I created an application which hosts a RESTful service in its own thread. When I close the application I noticed that some resources are still running. I would be very thankful if anyone could take a look at the code for initializing, starting and stopping the thread and suggest some better way for doing it. These are the methods...

What is the best way to run a continuous process in its own thread?

I created an application which has to periodically perform some tasks using threads. I am not sure if this is the best way for doing it so I would really appreciate if anyone could suggest a better way. This is the way I did it: This is the class which includes the functions for a continuous process (looking for inactive sessions and c...

How to Stop a Thread at a given point.

I was trying to stop some threads, read some things about the proper way to do it gracefully, but I must be doind something wrong because it simply doesn't work. At first I tried without the lock() with _IsRunning being volatile, then tried with the locks. Here is what I've got. private volatile bool _IsRunning; private static readonly ...

Why wont my JFrame hide ?

I'm in the process of creating a GUI in Netbeans 6.1 for my senior design project but i've run into an annoying snag. Temporary Windows like my login PopUp and others wont disappear when i tell it. I've been researching how to solve this for about 2 months on an off. I've even mad a separate thread for my Pop Up but it still wont work...

Passing data into a callback method (via BeginInvoke) in c#

I have the following code: delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount); string result; private int doStuff(int instanceNo, int sleepTime, int repeatCount) { for (int i = 0; i < repeatCount; i++) { Console.Write(instanceNo); Thread.Sleep(sleepTime); ...

Thread safety across shared instances (C#)

I use a factory pattern to create a custom object which is loaded from a cache if possible. There are no static members or functions on the custom object. Assuming 2 threads call the factory and are both returned references to the same object from the cache. (i.e. No new operator, in ref to answer below, object returned from a collectio...

Is there a way to search for and access Threads that are currently running?

Using Java 6: I have a method that uses a Thread to run a task in the background. This task accesses files, so the method should not be able to have multiple threads running. I am trying to figure out if there is a way that I can search for active Threads at the beginning of my method. I want to know if there is an active Thread that i...

Sync (oswego) vs Lock (JDK5)

Just to be sure, can experts confirm that java.util.concurrent.locks.Lock and Doug Lea's original Sync are basically the same thing but with different names. acquire vs lock release vs unlock Thanks. ...

communication with long running tasks in python

I have a python GUI app that uses a long running function from a .so/.dll it calls through ctypes. I'm looking for a way to communicate with the function while it's running in a separate thread or process, so that I can request it to terminate early (which requires some work on the C side before returning a partial result). I suppose th...

How to get the SPID in linux 2.6 from C++

Hi! I have a question: Is there some way to the SPID in linux 2.6 from a C++ application? When I do a "ps -amT" I can see the threads in the process: [email protected]:~# ps -amT PID SPID TTY TIME CMD 1120 - pts/1 00:00:20 sncmdd - 1120 - 00:00:00 - - 1125 - 00:00:00 - - 1126 - 00...

Are there any local DB that support multi-threading?

I tried sqlite, by using multi-thread, only one thread can update db at the same time.. I need multi-thread updating the db at same time. Is there are any DB can do the job? ps: I use delphi6. I found that sqlite can support multi-threading, But in my test of asgsqlite, when one thread inserting, others will fail to insert. I'm ...

MSMQ Thread Safety

I'm working with message queues in c#. I'm sending messages to a queue from code called by a timer (set up in the main thread), and also from a background worker thread. If I have two instances of the message queue, one for the timer and one for the background worker thread, am I going to face any thread issues? I have had problems when ...