multithreading

what is the best way to stop a thread in java?

I would like to stop a thread in mid execution. From reading around, I am of the thought I will have to check a local variable to determine if the thread should continue or clean up and exit run(). Any ideas of cleanly implementing this? ...

Signal handler, python

I have a multithreaded program and use the signal.signal(SIGINT,func) to kill all threads when ctrl c is pressed. The question I have is this: I have to call signal.signal(...) from main in python. Do I have to call that on a loop or can I just set it once and whenever the user presses ctrl c, the signal will be caught? ...

Problem in Updating DataGridView via a thread ( when Scrolling )

Hi Experts, I am stuck with this problem of mine and it will be great help if someone solves this problem for me What I am trying to do is : 1) Intialize a DataTable datatable in form load event and assign its defaultview to a datagridview dgvresult 2) On click of a button start an STA thread (I am actually working with WatIN IE ...

portable threading APIs

Hi all, I know of three portable threading C++ APIs : Qt boost::thread GNU Pth Apart from possible licensing issues involved, how do these compare in: actual portability (mostly interested in Linux and Windows) capabilities programming ease-of-use support/development activity of the library And: are there more like these that a...

How to wait for BackgroundWorker to finish and then exit console application

I have written a sample console application to test backgroundworker using one of the examples posted here in Stackoverflow. I have a backgroundworker which start with the main method but its ending in the middle of the operation if I press enter because I have written a console.readkey in the main method. But I want it to wait till the ...

How to make a Web (WCF) Service act as Windows Service

The question, I have a web application - .net 4. The client is having a requirement that he want to send email to his users on a regular basis about his new courses etc. The webapplication created will hosted on a "Shared hosting environment" with no excess to windows services - file system other than the web root folder through FTP....

NSRunLoops in Cocoa?

Hi guys, Let's say I have 2 threads, one is the main thread and another one, a secondary thread. The main thread is being used the most, but sometimes (rarely) I want the secondary thread to do some work based on calls from the main thread. Most of the time the secondary thread should sleep. Now after some searching I understand the wa...

Is iterating ConcurrentHashMap values thread safe?

In javadoc for ConcurrentHashMap is the following: Retrieval operations (including get) generally do not block, so may overlap with update operations (including put and remove). Retrievals reflect the results of the most recently completed update operations holding upon their onset. For aggregate operations such as putAll and clear,...

TPL vs. InvokeRequired/Invoke

Since .NET 4.0 there is the TPL to execute asynchronous tasks. If you are reading the msdn, all async operations interacting with forms / UI still uses the InvokeRequire ... Invoke() pattern. What I'm asking is that is there a reason for it? From what I learned, TPL should be sort of a replacement of older threading mechanisms. So what's...

Object disposal inside the thread

I'm programming a plug-in for a large system. The systems runs my plug-in in an independent thread. Inside the plug-in I'm allocating an unmanaged resource. I need to be 100% sure I release this driver. I implemented the IDisposable pattern and I covered all methods the system claims to call if the plug-in is about to be terminated. ...

Best pattern for "Do some work and quit"

I'm currently writing a little GUI program that does some work and exits afterwards. While work is done, the GUI thread is updated with infos for the user. This is the pattern I'm currently using and I'm thinking it's not the most elegant one: static void MainForm_Loaded(BeoExport exporter) { // Thread 1 runs the Export workerT...

Does using only immutable data types make a Java program thread safe?

Is it true that if I only use immutable data type, my Java program would be thread safe? Any other factors will affect the thread safety? *Would appreciate if can provide an example. Thanks! * ...

Threadpool, order of execution and long running operations

I have a need to create multiple processing threads in a new application. Each thread has the possibility of being "long running". Can someone comment on the viability of the built in .net threadpool or some existing custom threadpool for use in my application? Requirements : Works well within a windows service. (queued work can be...

NoClassDefFoundError in Java Applet on invokeLater()

I have an applet I've built using NetBeans, called AKApplet. It runs fine in the IDE, but when I put it in a web page it throws the following error: Exception in thread "Thread-15" java.lang.NoClassDefFoundError: AKApplet$2 at AKApplet.run(AKApplet.java:675) The applet uses the run() method to load some data in the background whil...

Thread-safe random number generation for Monte-Carlo integration.

Im trying to write something which very quickly calculates random numbers and can be applied on multiple threads. My current code is: /* Approximating PI using a Monte-Carlo method. */ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <omp.h> #define N 1000000000 /* As lareg as possible for increased ...

Synchronize() hangs up the thread

I'm writing a dll library in Delphi with multiple threads created by it. Let me describe the problem step by step. I'm sorry for a lengthy description in advance :-(. Let's forget about the library for a while. I created a windows application that is going to present views from several cameras. I created a window which is meant to show ...

Help with implementing Runnable in Java

Hello StackOverflow. I'm working on a java project with my team at work. To summarize, we have a main class that has a method that instantiates and calls a "Save" class. This "Save" class saves files back to a server with a couple of constructors and a handful of visible and non-visible methods. The class is CPU-intensive and time-...

Updating Button background for a brief time in Android (higlight it)

Hi, I have a button and I want to highlight it for a brief time. For e.g. it's a red button and it should be orange for a second and then turn red again. My code for this looks like the following: button.setBackgroundResource(R.color.orange); //highlight value button.invalidate(); try { Thread.sleep(3000...

Threads synchronizing in Java, IllegalMonitorStateException

Hello. I am trying to synchronize two threads - the "Main" thread, and a runnable. I get the IllegalMonitorStateException, but I do not completelty understand what "you do not have the lock of the object" means. Here is my code: public class ThreadsTest { private static ThreadsTest instance; public volatile boolean flag = fals...

Need help implementing multithreading into my TreeView (C#, WPF)

Okay, I have a TreeView that serves as a directory tree for Windows. I have it loading all the directories and functioning correctly, but it is pausing my GUI while it loads directories with many children. I'm trying to implement multithreading, but am new to it and am having no luck. This is what I have for my TreeView: private readon...