multithreading

Removing all queued tasks of an ThreadPoolExecutor

Hi StackOverflow, i have this rather simple question about the ThreadPoolExecutor. I have the following situation: I have to consume objects from a queue, create the appropiate worker tasks for them and submit them to the ThreadPoolExecutor. This is quite simple. But within a shutdown scenario many workers may be queued to execution. Si...

How to use SQLite in a multi-threaded application?

I'm developing an application with SQLite as the database, and am having a little trouble understanding how to go about using it in multiple threads (none of the other Stack Overflow questions really helped me, unfortunately). My use case: The database has one table, let's call it "A", which has different groups of rows (based on one of...

Atomic Operation C++

In C++, Windows platform, I want to execute a set of function calls as atomic so that execution doesn't switches to other threads in my process. How do I go about doing that? Any ideas, hints? EDIT: I have a piece of code like: someObject->Restart(); WaitForSingleObject(handle, INFINITE); Now the Restart() function does its work asy...

How do I kill a thread from another thread in Java?

I am calling two threads from a main thread, call them thread 1 and thread 2. When thread 1 stops, I want to stop or kill thread 2 also. How can I do this?There is a change in actual output what i want.That is There is a main class which is also thread.From main class i am calling thread1 and thread2.I am giving an input to thread1 from ...

Workflow 4.0 in a single threaded apartment?

I'm looking hard at WF 4.0 right now, but I'm having a hard time figuring out how to run workflows in STA threads. I've got a requirement for constructing XPS documents in a workflow, which means I need to create UI elements (FixedPage), which means the thread running the workflow has to be STA. In 3.0, you could do some magic (I didn'...

How to stop a running thread safely on user request?

I'm in a scenario when I have to terminate a thread while the thread is running according to user action on GUI. I'm using Qt 4.5.2 on Windows. One way to do that is the following: class MyThread : public QThread { QMutex mutex; bool stop; public: MyThread() : stop(false) {} void requestStop() { ...

Multiple Threads processing a Lists data

Hi all, I have a list of 300,000 + items. What i am currently doing with the list is validating the Address and writing both the original address and corrected address to a specified file. What i'd like to do is split the list evenly among a given number of threads and do processes on them concurrently. Can anyone help me with an exampl...

Web Based Stack Dump Tool for ASP.NET Using Mdbg?

There is a great presentation by Dan Farino, Chief Systems Architect at MySpace.com, showcasing a web-based stack dump tool that catalogues all threads running in a given process (what they're doing, how long they've been executing, etc.) Their techniques are also summarized on highscalability.com: PerfCollector. Centralized collect...

Multi-threaded BASH programming - generalized method?

Ok, I was running POV-Ray on all the demos, but POV's still single-threaded and wouldn't utilize more than one core. So, I started thinking about a solution in BASH. I wrote a general function that takes a list of commands and runs them in the designated number of sub-shells. This actually works but I don't like the way it handles acc...

C# Multithreading - Telling a waiting process that the first process has finished using the locked code?

I understand that when developing multithreaded applications you must synchronize access to shared memory using either, for instance, a monitor or a lock. QUESTION How do you tell the waiting process(proc2) that the process using the locked code block (proc1) has finished using the code? ...

C# How does a background thread tell a UI thread that it has finished doing something?

Scenario Lets say you have a C# WinForms application that doing some data processing. You have a method that retrieves data from a database that is called by the UI thread. The background thread then runs off to do this task. You want the UI to carry on doing its thing and not be locked up and unresponsive. QUESTION How do you let the...

Threads not copied while forking?

I have one application which has several different threads. Then I forked with fork() but found the child process has to recreate those threads. Is that possible to copy the threads during the clone? Thanks! ...

How to organize ASP.NET request locking or row locking in DB

Hi! I've asp.net page/handler to access images. When performed fist request to the image I resize image to standard size(save on disk) and return it. So I need lock all request to the image except one. This one will resize image. Image identified by ID in URL, so I guess one lock object required per one image(ID in URL). My question is H...

Abort a thread?

I want to implement interruptable tasks based on background threads. What is the cleanest way to implement the TTask.Stop method? How can I abort the background thread? The code executed within the thread context is passed to the task using an anonymous method and can contain blocking calls, so I can't rely on the fact, that the Termina...

Creating a thread in DllMain?

It seems that when a thread is created from within DllMain upon DLL_PROCESS_ATTACH it won't begin until all dll's have been loaded. Since I need to make sure the thread runs before I continue, I get a deadlock. Is there any way to force the thread to start? ...

Determining execution time of a thread and IO accesses by different threads

Hello I want to determine execution time of a thread in a multi-threaded program, and I also want to know about IO accesses made by each thread. Is there any command/tool which can do this for C programs? ...

Mysterious pointer-related multithreading slowdown

Background: So I'm working on a raytracer.. for my construction of the spatial partitioning scheme, I initially had some code like this: if (msize <= 2) { // create a leaf node Model **models = new Model*[msize]; for (uint i=0; i<msize; ++i) models[i] = &mlist[i]; *arrayPtr = Node(models, msize); // class Node contai...

Must i abort this thread? Waiting for namedpipes. How do i do this properly?

I have another question about this same code and keeping the pipe open after the client closes it But here i have a problem gracefully terminating my app. My main code is below. There are 2 problems. 1) I am using Thread.Abort and 2) This application doesnt actually end. I can set a breakpoint and see abort is called and step to the end...

Why is a threaded version of this particular Perl script 200 times slower than its non-threaded counterpart?

A presentation by Mikhael Goikhman from a 2003 Perl conference includes a pair of examples of prime-number-finding scripts. One is threaded, and the other is not. Upon running the scripts (print lines commented out), I got an execution time of 0.011s on the non-threaded one, and 2.343 (!) seconds on the threaded version. What accounts fo...

when do we go for multithreading in c#?

Hi, I know how to implement multithreading using c#. But I want to know how is it working like. will only one thread run at a time and when that thread is waiting will it execute the second thread? If the second thread is executing and the first thread is ready. What will happen? Which thread will be given the priority? I am confused...