multithreading

What is "cancellationToken" in the TaskFactory.StartNew() used for?

http://msdn.microsoft.com/en-us/library/dd988458.aspx UPD: so, let's discuss this article then: http://msdn.microsoft.com/en-us/library/dd997396.aspx I've changed that code a little: static void Main() { var tokenSource2 = new CancellationTokenSource(); CancellationToken ct = tokenSource2.Token; ...

c# multithreading - Is there a need to lock when writing to DB?

Hi All, I've got a multithreaded C# 2.0 app where each thread writes some results into a SQL server 2000 database table. There is only a straight INSERT command and no other logic. My question is - do I need to put a lock around the methods that writes the results to the database? There is a lock at the moment but I suspect that it's s...

why does `try_lock`s performance behaves always like `lock`on a mutex?

On a mutex: I was asking about the performance of lock here and about the performance of try_lock here. The question about try_lock was closed as exact duplicate to the one about lock. However, I fail to see why try_lock must behave in the same way as lock in every possible mutex implementation. As this question was not really answered...

Java synchronized question

I'm new to Java Threads and synchronization. Lets say I have: public class MyClass(){ public synchronized void method1(){ //call method2(); } public synchronized void method2(){}; } What does it mean when I synchronize a method1() on an instance object? So when a thread acquired the lock when trying to acce...

DataGridView blocks the UI Thread

I am working on application which uses a DataGridView control. Since there is a lot of data I use the VirtualMode to use paging, but even with this feature this take a while to update DataGridView. So I created a control which spins and entertain an user. Unfortunately there are some issues with this solution, namely when the entertainme...

Python GTK/threading/sockets error

I'm trying to build a Python application using pyGTK, treads, and sockets. I'm having this weird error, but given all the modules involved, I'm not entirely sure where the error is. I did a little debugging with some print statements to narrow things down a bit and I think the error is somewhere in this snippet of code: self.sock = ...

CPU Intensive Calculation Examples?

I need a few easily implementable single cpu and memory intensive calculations that I can write in java for a test thread scheduler. They should be slightly time consuming, but more importantly resource consuming. Any ideas? ...

A question about java multithreading.

In Java, I know that the default thread priority is 5. I have a class which basically sleeps for n number of seconds while doing other stuff on the side. If I create 20 threads in random order, each with that class as the target with n being either 10 or 20 seconds, how is it that all the 10 second ones finish first, and then the 20 seco...

Mutual Exclusion for N Asynchronous Threads

I've got an asynchronous application, meaning that at any given time there can be N events. Is there a known algorithm for doing mutual exclusion for N threads, without hardcoding each thread to have an ID? ...

Try to make a process that can TSKILL itself

So I have a problem with a process that I am running, whenever I try to stop it using process.destroy(), it does not stop. I want to create a file (ProcessHandler) that extends Process and do the following: ProcessHandler process = (ProcessHandler)Runtime.getRuntime().exec("cmd.exe /c \"java net/com/codeusa/Server 43594\""); So, my p...

performSelectorInBackground: on main thread

I know this is a wack question, but it is valid to performSelectorInBackground: on an iPhone apps' main thread? I am aware of performSelectorOnMainThread: but I was just wondering if performSelectorInBackground: can also be used on the main thread. My understanding is it cannot, because performSelectorInBackground: spawns a new thread ea...

java server to handle multiple tcp connections

hi, im trying to write a simple web server in java. right now ive only got a simple program but id like to extend it so that it can serve multiple browsers by establishing multiple tcp connections. ive been reading about threading. my understanding is that you can make a new thread and that will continue as if its another program ent...

Threading problems in Java

I have the following problem. My J2ME app goes totally dead. I though it was a deadlock, but using NetBeans' built-in functionality, it couldn't find such. After some time however, it started throwing out the following messages in the console: 8242276 - CORE - CRITICAL - 2 - **event queue 3 full, dropping event 8242284 - CORE - CRITICA...

In WPF is the UI dispatcher.begininvoke method thread safe?

I have a WPF app that makes use of some multi threading. I am curious to know if calling into the UI thread by using the Dispatcher.BeginInvoke() method considered thread-safe? Normally i would use the lock statement to make sure only one thread can access a variable. Would the following be thread-safe in a WPF app? this.Dispatcher.B...

Is it possible to create a thread that doesn't exit even when main thread exits in windows using c/c++?

Like in the above graph,all other threads will automatically exit once the main thread is dead. Is it possible to create a thread that never dies? ...

How do I test this method's expected behavior in Java: it spawn a thread, and throws an exception under certain conditions

Suppose that I have a method which spawns a new thread and do some work. Under certain conditions, the newly spawn thread would throw a certain type of exception, which terminates the entire process. I would like to write JUnit tests to verify this behavior. Is there a way to do it? The method is: private void foo() { new Thread() { ...

.NET Parallel.ForEach, StreamWriter output + thread safe

Hi, In the past I have used ThreadPool.QueueUserWorkItem to spawn multiple threads from a manager class. This manager class subscribes to an event in these spawned threads which is raised when the thread work completes. The manager class can then handle writing output to a text file by using a lock to prevent any race conditions. Now I...

How to kill a thread and handler before going to new activity...

Hey all - this code might be a bit messy in the way I'm trying to clean up the handler as I've been trying to track down where the crash happens... I've got a dialog activity that is showing a password entry with a progressbar being animated by a thread and handler... It seems that when I'm attempting to see if the progressbar is done,...

Restart a task or create a new one? c#

I'm working on a project that creates like 20~50 new tasks every 30~80 seconds. Each task lives for 10~20 seconds. So I'm using a Timer to create those new tasks, but everytime I always recreate the same task, the code is like this: public class TaskRunner : IDisposable { private readonly Timer timer; public IService service; ...

Thread causes crash when exiting a view - result of code change to prevent UIActivityIndicatorView not displaying, UIImageView not hiding.

When an image is loading, I want to hide the old image and display an activity indicator. The following code should (IMO) work, however, the image does not hide and no activity indicator is displayed. If the image has not been downloaded previously, there is a discernable wait whilst it does download. What am I doing wrong? - (UIImage *...