multithreading

How to check if Thread finished execution

I have following problem: I want to check (C#) if thread has finished execution, i.e. if the thread method returned. What I do now is call Thread.Join(1), but this gives 1 ms delay. Is there any way to simply check if thread finished. Inspecting Thread.ThreadState just seems too cumbersome. ...

Python Locking Implementation (with threading module)

This is probably a rudimentary question, but I'm new to threaded programming in Python and am not entirely sure what the correct practice is. Should I be creating a single lock object (either globally or being passed around) and using that everywhere that I need to do locking? Or, should I be creating multiple lock instances in each...

Best way to reuse a Runnable

I have a class that implements Runnable and am currently using an Executor as my thread pool to run tasks (indexing documents into Lucene). executor.execute(new LuceneDocIndexer(doc, writer)); My issue is that my Runnable class creates many Lucene Field objects and I would rather reuse them then create new ones every call. What's t...

Real World Examples of read-write in concurrent software

I'm looking for real world examples of needing read and write access to the same value in concurrent systems. In my opinion, many semaphores or locks are present because there's no known alternative (to the implementer,) but do you know of any patterns where mutexes seem to be a requirement? In a way I'm asking for candidates for the s...

How to use a delay in a swing application

I am building a swing application. At some point, I have to start an "animation": ... jpanel1.setBackground(Color.Black); Delay(milli) jpanel1.setBackground(Color.White); ... and so on. The gui itself and all the logic behind it work.It is just this time depended color-changing that does not. I have read, that swing is not threa...

SQLite multi process access

Hello, We are using SQLite in a multi processes and multi threaded application. The SQLite database files are encrypted using the embedded SQLite encryption. The FAQ states that SQLite should be able to manage multi process accesses using locks mechanism. We are experiencing a strange problem: When many threads are accessing the same da...

Parallel features in .Net 4.0

I have been going over the practicality of some of the new parallel features in .Net 4.0. Say I have code like so: foreach (var item in myEnumerable) myDatabase.Insert(item.ConvertToDatabase()); Imagine myDatabase.Insert is performing some work to insert to a SQL database. Theoretically you could write: Parallel.ForEach(myEnume...

.NET Process.Kill() in a safe way

I'm controlling a creaky old FORTRAN simulator from a VB.NET GUI, using redirected I/O to communicate with the simulator executable. The GUI pops up a "status" window with a progress bar, estimated time, and a "STOP" button (Button_Stop). Now, I want the Button_Stop to terminate the simulator process immediately. The obvious way to do t...

Multithreaded Delegates/Events

I am trying to disable parts of the UI in a .NET app based on polling done on a background thread. The background thread checks to see if the global database connection the app uses is still open and operable. What I need to do, and would prefer to do it without polling on the UI thread, is to add an event handler that can be raised by...

Stopping a runaway Lua subprocess

I have embedded Lua in an Objective-C application using LuaObjCBridge. I need to know how to stop the Lua process if it taking too much time (infinite loop?). Would running it in a separate thread help? ...

Issue with Java join() method.

First of all here are some code snippets: public void startThread() { this.animationThread = new Thread(this); this.animationThread.start(); try { this.animationThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } } @Override public void run() { pirateMainAnimation.animat...

Why does this method throw an IllegalMonitorStateException?

public static synchronized void main(String[] args) throws InterruptedException { Thread t = new Thread(); t.start(); System.out.print("X"); t.wait(10000); System.out.print("Y"); } What is the problem with this method? How can I avoid such problems from now on? ...

Why wait should always be in synchronized block

Hi gents, We all know that in order to invoke Object.wait() , this call must be placed in synchronized block,otherwise,IllegalMonitorStateException is thrown.But what's the reason for making this restriction?I know that wait() releases the monitor, but why do we need to explicitly acquire the monitor by making particular block synchroni...

Thread Local Storage and local method variables

In c#, each thread has its own stack space. If this is the case, why is the following code not thread-safe? (It is stated that this code is thread-safe on this post: Locking in C# class Foo { private int count = 0; public void TrySomething() { count++; } } As count is an int (stack variable), sur...

How to make different threads execute different parts in CUDA ?

I am working on CUDA and I have a problem related to thread synchronization. In my code I need threads to execute different parts of the code, like: one thread -> all thread -> one thread -> This is what I want. In the initial part of code only one thread will execute and then some part will be executed by all threads then again sing...

Guidelines of when to use locking

I would like to know if there are any guidelineswhich a developer should follow as to when (and where) to place locks. For instance: I understand that code such as this should be locked, to avoid the possibility of another thread changing the value of SomeHeapValue unexpectedly. class Foo { public SomeHeapObject myObject; public v...

Servlet doesnt appear to execute in a threaded manner

I have developed a simple server using Tomcat which runs a servlet. The servlet calls a command line program - which takes about 20 seconds to execute then returns the result to the user via JSON. The problem is - if i make above 2 simultaneous requests, the servlet blocks until one of the previous requests is completed. An example of...

Java - Multithreading

I have a question... Can we call thread_object.start() from within a constructor ? Is this approach a good idea ? Thanks. ...

c++ : looking away to implemnt this senario

Hi im looking to find how to implement this scenario: i have logic code that is inside function, now i like to be able to execute this function in a separate thread. now what i have is a raw implementation of this .. i simple Init the Thread that in its Start/Run method i keep the function logic . how can i make it more generic ? so i c...

Multi-threaded downloader in C# question

Currently I have multi-threaded downloader class that uses HttpWebRequest/Response. All works fine, it's super fast, BUT.. the problem is that the data needs to be streamed while it's downloading to another app. That means that it must be streamed in the right order, the first chunk first, and then the next in the queue. Currently my dow...