multithreading

[WPF] Updating a 2nd window control from events in an object created in the 1st window

Hi, here's what I need (it's a bit hard to explain): I have 2 window controls: MainWindow and FileMover and 1 util class: FileMonitor MainWindow created a new object of FileMonitor for testing purposes on it's Loaded event, which creates a FileSystemWatcher and a Timer object. The FileSystemWatcher watches a given folder for Created an...

How would I wait for multiple threads to stop?

I have a Main thread that spawns around 20 worker threads. I need to stop the Main thread until all the other threads are finished. I know about (thread).Join. But that only works for one thread. and multiple Joins hurt performance like this. t1.Join() t2.Join() ... t20.Join() as the program waits one by one for each to stop. How wou...

Thread Pool and .IsBackground in .NET

MSDN, as well as many other sources, claim that worker threads in the thread pool are always background. "Thread pool threads are background threads." (MSDN) "Pooled threads are always background threads." (Threading in C#, Joseph Albahari) I can easily make the worker thread non-background by setting Thread.CurrentThread.I...

java: wait until another thread performs a statement n times

Hi, what is the best way to stop a thread and wait for a statement (or a method) to be executed a certain number of times by another thread? I was thinking about something like this (let "number" be an int): number = 5; while (number > 0) { synchronized(number) { number.wait(); } } ... synchronized(number) { number--; number....

Unable to get thread dump? Any ideas why my app blocks?

I have a basic java server app that has 100 worker threads that do simple HEAD requests on urls. I'm using HttpClient 4.x for this. A few minutes into the run my program just freezes for a couple minutes and I cannot figure out why. Check out the screen shot of what visual vm monitor reports. You can see it flatline. During this time I...

Separate thread for Java game logic

When I have made simple single thread games I implemented the game logic in much the same way that the increasingly famous Space Invaders tutorial does as shown below: public static void main(String[] args) { //This is the COMPLETE main method Game game = new Game(); // Creates a new game. game.gameLogic(); // Starts running gam...

python threadpool problem (wait for something)

I wrote simple web site crowler with threadpool. The problem is: then crawler is get all over site it must finish, but in real it wait for something in the end,and script dont finished, why this happend? from Queue import Queue from threading import Thread import sys from urllib import urlopen from BeautifulSoup import BeautifulSoup, S...

How to increase thread priority in pthreads?

I am using pthread in Linux. I would like to increase the thread priority by setting the parameters sched_param.priority. However, I could not find much info from the net regarding the range of the thread priority I could set, or about the description of the thread priority. Also, I would like to know about the relative thread priority ...

Create concurrent HashMap in webapp

What is the best way to make threadsafe HashMap in Tomcat ?I'm going to create ConcurrentHashMap on InitServlet once on load on my application. (<load-on-startup>1</load-on-startup>) Requests from different threads will read and write data to my ConcurrentHashMap. I'm not good in mutlithreading, so not sure is it approach correct? A...

C++ volatile keyword with global shared variable accessed by function

Hi, I have a multi-threaded C++ application. Now I know that for global shared variables, you should use volatile in some cases while checking the state of the variable or else the compiler could assume that the variable's value never changes (in that thread). What if, however, instead of checking the status of a variable I call a...

How to make the current thread wait for a function to return in java?

I have a function in which the processing is given over to a new thread. The problem is the place where the function is called from does not wait for the function to return and promptly executes whatever code was there after the function call. How do I wait for the function to return so no code after it gets executed until its returned?...

Gui reentrancy with managed waiting

Hello, I've found a reentrancy problem when using NotifyIcons. It's really easy to reproduce, just drop a NotiftIcon on a form and the click event should look like this: private bool reentrancyDetected; private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { if (reentrancyDetected) MessageBox.Show("Reentrancy"); ...

how efficient is locking an unlocked mutex? how much does a mutex costs?

Hi, In a low level language (C, C++ or whatever): I have the choice in between either having a bunch of mutexes (like what pthread gives me or whatever the native system library provides) or a single one for an object. How efficient is it to lock a mutex? I.e. how much assembler instructions are there likely and how much time do they t...

how efficient is a try_lock on a mutex?

Possible Duplicate: how efficient is locking an unlocked mutex? how much does a mutex costs? How efficient is a try_lock on a mutex? I.e. how much assembler instructions are there likely and how much time are they consuming in both possible cases (i.e. the mutex was already locked before or it was free and could be locked). ...

java jprogressbar hangs during heavy operation

I'm writing a java program and, before I call a method that makes heavy use of the CPU, I display a frame with a JProgressBar on it. Although I display it before the method is called, the JProgressBar is not shown until the method is over. The progress bar does not interact with the method in any way (yet) and that's why I am confused. I...

backgrounds tasks by swingworkers become sequential

Hi, I am using SwingWorkers to make my GUI responsive. But I can not understand the following: I have a remote method I want to call from the GUI as the user presses a button. I have inside the action of the button (short for presentation of problem): //in action of button SwingWorker worker = new SwingWorker<boolean,Void>(){ @Over...

Mixing Qt threads with COM threads

I'm working on a little project that uses DirectShow/COM for capture, and DShow makes callbacks using its own threads when my application gets imaging data. I'm also using Qt in my project, and I'm wanting to use Qt for synchronisation and thread-safety. I'm wondering how I can use Qt Threads in this case. I understand I can also use W...

criticism this python code (crawler with threadpool)

Hi, how good this python code ? need criticism) there is a error in this code, some times script do print "ALL WAIT - CAN FINISH!" and freeze (no more actions are happend..) but i can't find reason why this happend? site crawler with threadpool: import sys from urllib import urlopen from BeautifulSoup import BeautifulSoup, SoupStrainer...

How to lock a file to a thread when serializing?

I'm building a generic xml repository that uses a datacontractserializer to serialize/deserialize the files and I'm unsure as how to ensure that the files cannot be altered when they are being read. My code to read all files is like this: public IQueryable<T> All<T>() where T : class, new() { List<T> instances = ...

Delphi 2010: No thread vs threads - TSQLConnection and TSQLDataSet

Hi everyone, My previous question From the above answer, means if in my threads has create objects, i will face the memory allocations/deallocations bottleneck? I've a case that I need to create TSQLConnection and TSQLDataSet to query data from 5 tables of the database, each table has more than 10000 records. So I will create 5 thread...