multithreading

Multitasking how to make worker thread gain control after calling infinite loop function

assume creating 3 worker threads by pthread_create, in these worker thread routine, each call a simple infinite loop function which do not have a return to do counting how to make worker thread gain control after calling infinite loop function and save the context of infinite loop function for calling in worker thread again? ...

Sharing an object between threads

How would you set the object data that is shared between threads and needs to be updated once after the complete cycle of (say) two threads in busy loop? CRITICAL_SECTION critical_section_; int value; //needs to be updated once after the cycle of any number of threads running in busy loop void ThreadsFunction(int i) { while (true) ...

Thread & Windows forms

I'd like to know if the executing thread is the one that created a given control instance (to prevent cross-thread if it's not). Is that possible ? ...

how to clear stack after stack overflow signal occur

In pthread, After reaching yellow zone in stack, signal handler stop the recursive function by making it return however, we can only continue to use extra area in yellow zone, how to clear the rubbish before the yellow zone in the thread stack ? (Copied from "answers"): #include <pthread.h> #include <stdio.h> #include <stdlib.h> ...

Run a external program with specified max running time

I want to execute an external program in each thread of a multi-threaded python program. Let's say max running time is set to 1 second. If started process completes within 1 second, main program capture its output for further processing. If it doesn't finishes in 1 second, main program just terminate it and start another new process. H...

Have threads run indefinitely in a java application

I am trying to program a game in which I have a Table class and each person sitting at the table is a separate thread. The game involves the people passing tokens around and then stopping when the party chime sounds. how do i program the run() method so that once I start the person threads, they do not die and are alive until the end o...

C run function in another thread

Hello, I have simple from written on C/gtk+ and i have function in this appliction. I need to run this function in a separate thread from gui form. Where can i see example? Thank you. ...

Restoring database with SMO - Reporting progress problems

I'm using the below to restore a database in VB.NET. This works but causes the interface to lockup if the user clicks anything. Also, I cannot get the progress label to update incrementally, it's blank until the backup is complete then displays 100% Sub DoRestore() Dim svr As Server = New Server("Server\SQL2008") Dim res As Rest...

Cache consistency & spawning a thread

Background I've been reading through various books and articles to learn about processor caches, cache consistency, and memory barriers in the context of concurrent execution. So far though, I have been unable to determine whether a common coding practice of mine is safe in the strictest sense. Assumptions The following pseudo-code i...

How to re-use a thread in Java ?

I am a building a console Sudoku Solver where the main objective is raw speed. I now have a ManagerThread that starts WorkerThreads to compute the neibhbors of each cell. So one WorkerThread is started for each cell right now. How can I re-use an existing thread that has completed its work? The Thread Pool Pattern seems to be the solut...

Non-reentrant C# timer

I'm trying to invoke a method f() every t time, but if the previous invocation of f() has not finished yet, wait until it's finished. I've read a bit about the available timers (this is a useful link) but couldn't find any good way of doing what I want, save for manually writing it all. Any help about how to achieve this will be appreci...

Matrix Multiplication with Threads: Why is it not faster?

Hey all, So I've been playing around with pthreads, specifically trying to calculate the product of two matrices. My code is extremely messy because it was just supposed to be a quick little fun project for myself, but the thread theory I used was very similar to: #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define M ...

Producer / Consumer - I/O Disk

Hi, I have a compressed file in the disk, that a partitioned in blocks. I read a block from disk decompress it to memory and the read the data. It is possible to create a producer/consumer, one thread that recovers compacted blocks from disk and put in a queue and another thread that decompress and read the data? Will the performance ...

Adding row to DataGridView from Thread

Hello, I would like to add rows to DataGridView from two seperate threads. I tried something with delegates and BeginInvoke but doesn't work. Here is my row updater function which is called from another function in a thread. public delegate void GRIDLOGDelegate(string ulke, string url, string ip = ""); private void GRIDLOG(str...

Does add() on LinkedBlockingQueue notify waiting threads?

I have a consumer thread taking elements from a LinkedBlockingQueue, and I make it sleep manually when it's empty. I use peek() to see if the queue empty because I have to do stuff before sending the thread to sleep, and I do that with queue.wait(). So, when I'm in another thread and add()an element to the queue, does that automatical...

Python C API from C++ app - know when to lock

Hi Everyone, I am trying to write a C++ class that calls Python methods of a class that does some I/O operations (file, stdout) at once. The problem I have ran into is that my class is called from different threads: sometimes main thread, sometimes different others. Obviously I tried to apply the approach for Python calls in multi-threa...

The way cores, processes, and threads work exactly?

I need a bit of an advice for understanding how this whole procedure work exactly. If I am incorrect in any part described below, please correct me. In a single core CPU, it runs each process in the OS, jumping around from one process to another to utilize the best of itself. A process can also have many threads, in which the CPU core r...

What's the accepted way to write a C# TSR?

I'm using C# to write a WCF router which I want to stay running without using the Console.ReadKey "hack". I was wondering if there's an accepted way to do this within C# that's more elegant than while (true) Thread.Sleep(100); ...

Wait between tasks with SingleThreadExecutor

I am trying to (simply) make a blocking thread queue, where when a task is submitted the method waits until its finished executing. The hard part though is the wait. Here's my 12:30 AM code that I think is overkill: public void sendMsg(final BotMessage msg) { try { Future task; synchronized(msgQueue) { t...

Python Threading

I'm trying to make a simple program that continually displays and updates a label that displays the CPU usage, while having other unrelated things going on. I've done enough research to know that threading is likely going to be involved. However, I'm having trouble applying what I've seen in simple examples of threading to what I'm try...