multithreading

Asynch Design C#

I am writing a crawler in C# that starts with a set of known url's in a file. I want pull the pages down asynch. My question is what is the best pattern for this, i.e. Read file into List/Array of urls, Create an array to store completed urls? Should I create a 2 dimensional array to track status of threads and completion? Also some othe...

Want to convert process into a multi-threaded process

Let me go over what my code is doing (haven't coded it yet), I want to make it run in multiple threads to speed things up. looks for a record in the database that hasn't been processed yet: SELECT TOP 1 * FROM Products WHERE isActive = 1 looks up a URL (Rest call), returns back the HTML and stores it in the database Sets the flag for...

Suspend and resume the main thread in C++ for Windows

I need to be able to suspend and resume the main thread in a Windows C++ app. I have used handle = GetCurrentThread(); SuspendThread(handle); and then where is should be resumed ResumeThread(handle); while suspending it works, resuming it does not. I have other threads that are suspended and resumed with no problems, is there somet...

Is it possible that a single-threaded program is executed simultaneously on more than one CPU core?

When I run a single-threaded program that i have written on my quad core Intel i can see in the Windows Task Manager that actually all four cores of my CPU are more or less active. One core is more active than the other three, but there is also activity on those. There's no other program (besided the OS kernel of course) running that wou...

If I want to find truly experience the pain of writing multi-threaded applications, What program should I try writing?

Hi, If I want to find truly experience the pain of writing multi-threaded applications, What program should I try writing? Note, I would like to know of an example that is not too big and serves as a good example of demonstrating the intricacies for teaching purposes. thanks ...

Can i use boost::threadpool as a 'thread-safe queue'?

What I need is actually a thread-safe queue structure, where multiple clients keep dumping data into the queue and one working thread keeps processing and popping the queue is there any well-established solution existing in STL or Boost? I now think about using Boost::threadpool to do this. Simply set the number of parallel threads to ...

java: How do I stop a thread that waits for long periods

i hava a program connect to server through xot (x25 over tcp/ip) protocol. i have a thread to connect, send recv data with server using xot library. public class MyThread extends Thread{ public MyThread() { } @Override public void run(){ // init sock ... // connect to server sock.conne...

Thread.isInterrupted doesn't work, Thread.interrupted does

The following program demonstrates the problem (latest JVM & whatnot): public static void main(String[] args) throws InterruptedException { // if this is true, both interrupted and isInterrupted work final boolean withPrint = false; // decide whether to use isInterrupted or interrupted. // if this is true, the program n...

Why is AsynchResult stored in System.Runtime.Remoting.Messaging in the .NET framework ?

Hi, Just out of curiosity, does anyone know why the AsynchResult type resides in System.Runtime.Remoting.Messaging as opposed to System.Threading ? It would seem to make more sense to have it declared with all threading types. Thanks, Scott ...

Can I switch user on runnable thread in Java ?

Suppose I need to run this on shell, $ su <user>; cp /x /y; Is there a way to run threads with another unix user within the application ? ...

How is threadsafty guranteed with @PersistenceContext?

According to many examples it is possible to inject an EntityManager into @Stateless or @Singleton EJBs like this: @Stateless // or @Singleton public class MyRepository { @PersistenceContext private EntityManager em; ... } The EJB 3.1 Spec says that dependency injection is only performed at construction time, so that all call...

Which Java APIs create Threads

Without having the source code for a Java API, is there anyway to know if the API methods create multiple threads ? Are there any conventions to follow if you are writing Java APIs and they create multiple threads. This may be very fundamental question but it happened to spawn out of a discussion in which the crux question was - " How do...

Threading Library for Multithreaded Windows Service

Hi, I'm looking for a good library, preferably in C#, which I can use in a windows service and it will handle all the multithreading functionality needed. The service will run every x minutes, check a database for processes to call, and for each of them spawn a thread and run it. Each thread should handle exceptions, logging and such...

How to create a dynamic number of threads?

Currently I create a thread the following way (the normal way) Public loginThread As Thread Public loginThreadStart As New ThreadStart(AddressOf LogIntoWhatever) Public callLoggedIn As New MethodInvoker(AddressOf loggedIn) However, what I want to be able to do is something along the lines of (this obviously does not work, and is entir...

What is the easiest way to parallelize a task in java?

Say I have a task like: for(Object object: objects) { Result result = compute(objects); list.add(result); } What is the easiest way to parallelize each compute() (assuming they are already parallelizable)? I do not need an answer that matches strictly the code above, just a general answer. But if you need more info: my tasks ...

Multithreading working perfectly until I hit the com object.

I'm using com interop to talk to some physical piece of hardware. When I need the current reading from the hardware I have a nice elaborate piece of threading code that keeps it off my UI thread so that I don't lock up the UI while I query the hardware since sometimes it can take as much as 1-2 minutes (although usually more like 1-5 se...

Java concurrency question - synchronizing on a collection

Will the following code snippet of a synchronized ArrayList work in a multi-threaded environment? class MyList { private final ArrayList<String> internalList = new ArrayList<String>(); void add(String newValue) { synchronized (internalList) { internalList.add(newValue); } } boolean find(Stri...

Safety nets in complex multi-threaded code?

As a developer who has just finished writing thousands of lines of complex multi-threaded 'C' code in a project, and which is going to be enhanced, modified etc. by several other developers unfamiliar with this code in the future, I wanted to find out what kind of safety nets do you guys try to put in such code? As an example I could do ...

Are there thread group-local variables in Java?

I am looking for a class similar to ThreadLocal which would work on thread groups instead of threads. If there is not such a class (in some open source library) how would you implement it? Some better idea than having thread groups in WeakHashMap? I am implementing a debugging framework tunable in run-time with various parameters in gl...

Python Thread Pause and Wait

I have an array of threads. Each of them call the run method continuously. At the end of each run method I want them to pause and wait. How can I get the threads to execute one at a time, and then continue the loop when all are finished? I need them to ALWAYS execute in order (ie: 1, 2, 3, 4 - 1, 2, 3, 4...) I'm currently using threadi...