multithreading

Best practices for Java logging from multiple threads?

I want to have a diagnostic log that is produced by several tasks managing data. These tasks may be in multiple threads. Each task needs to write an element (possibly with subelements) to the log; get in and get out quickly. If this were a single-task situation I'd use XMLStreamWriter as it seems like the best match for simplicity/funct...

JMX Thread stuck on ClientNotifForwarder

Our application connects to several jmx agents (about 50) to poll jmx data in frequent interval. After some time (about a day) application becomes irresponsive. We looked at thread dump and seeing large number of threads stuck on ClientNotifForwarder.. Eg: "ClientNotifForwarder-50" daemon prio=3 tid=0x09aa3800 nid=0x330 runnable [0xd3...

c# Threads and display update

Hi! I have a Windows Form with a label and a picture box. To retreive an image from a web service I use a thread. The user click on a button and first the label must be displayed and then new thread is started to retrieve the image. This is the code: private void menuItem1_Click(object sender, EventArgs e) { etiquetaCargando.Visible...

Deadlocks with pthreads and CreateThread

I'm using pthreads in a Windows application. I noticed my program was deadlocking--a quick inspection showed that the following had occurred: Thread 1 spawned Thread 2. Thread 2 spawned Thread 3. Thread 2 waited on a mutex from Thread 3, which wasn't unlocking. So, I went to debug in gdb and got the following when backtracing the th...

Weird lock() behavior with foreach

Hi everyone, So, this isn't my code and has been shortened to show the behavior, but it is giving very unexpected results. I have two function in a class and a lock object mylock = new object(); List<string> temp = new List<string>(); Func1(string) { lock(mylock) { temp.Add(string); } } Func2() { lock(mylock) { tem...

Using Linq-to-XML to insert, with threading

What is the best way to ensure thread-safe Linq-to-XML, for writing? We recently got overloaded on our web cluster and I had to pull a quick overloaded.aspx out of my butt to capture emails that people can be contacted with later when the site becomes more responsive. In my short 5 minute haste, I wrote this: private static object Loc...

How do I get two thread to insert specific timestamps into a table?

I created two (or more) threads to insert data in a table in database. When inserting, there is a field CreatedDateTime, that of course, stores the datetime of the record creation. For one case, I want the threads to stay synchronized, so that their CreatedDateTime field will have exactly the same value. When testing with multi threadi...

Are Ruby class member variables OK now?

Hi, Last May at Railsconf on Portland, I went to a presentation where it was argued that, in Rails, Ruby class member variables, like @@foo, are dangerous because they are inherently unthreadsafe. I researched the question afterward and I never found a link that really fleshed out the question. I would appreciate a pointer to a good ...

How do I use WaitHandles safely to prevent deadlocks?

Observe the following pseudo: ManualResetEvent[] resetEvents = new ManualResetEvent[operations.Count]; for( int i = 0; i < operations.Count; i++ ) { resetEvents[i] = new ManualResetEvent(false); ThreadPool.QueueUserWorkItem(new WaitCallback(timeConsumingOpHandler), resetEvents[i]); } WaitHandle.WaitAll(resetEvents); In the case ...

c# threads and properties

Hi! I want to read two properties from a worker thread. Here it is an example of the class: public partial class FrmPrincipal : Form { private int Height; private int Width; private string token; public FrmPrincipal() { InitializeComponent(); ... } private void menuItem1_Click(object sender...

How to keep track of thread progress in Python without freezing the PyQt GUI?

Questions: What is the best practice for keeping track of a tread's progress without locking the GUI ("Not Responding")? Generally, what are the best practices for threading as it applies to GUI development? Question Background: I have a PyQt GUI for Windows. It is used to process sets of HTML documents. It takes anywhere from t...

TMonitor synchronization / Application.ProcessMessages

Hello again! I'm back with another question concerning threads and synchronization. Imagine a server application that has to perform a lengthy operation and the client wants his GUI to remain responsive while he waits for the server's response. I thought of the following pattern: TMonitor.Enter (FTCPClient); try WorkerThread := TWorke...

c# threads and properties second part

I have this code: public partial class FrmPrincipal : Form { private Image imagen; public FrmPrincipal() { InitializeComponent(); ... } private void menuItem1_Click(object sender, EventArgs e) { Thread t = new Thread(RequestImage); t.Start(); } private void RequestImage(...

Why don't large programs (such as games) use loads of different threads?

I don't know how commercial games work inside very much, but the open source games I have come across don't seem to be massively into threading. Same goes for most other desktop applications, normally two or three threads seem to be used (eg program logic and GUI updates). Why don't games have many threads? Eg separate threads for physi...

boost::thread: Segfault when running optimized version

I have trouble getting boost:thread to work. It runs fine when compiling without optimization: g++ -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread But a version that's compiled with optimizations crashes g++ -O2 -o test-thread test-thread.cpp -lboost_thread-gcc-mt-s -lpthread ./test-thread Segmentation ...

What kind of method to use for communications when planning multilayer flash server

Hello all im planning to build flash multilayer server ( in c++ or java ) im not coming from the flash area . But from what im reading flash does support sockets , BUT this is not my case i need to be able to support browser flash games so it leaves me with port 80 with http .but how can i implement good communication architecture wit...

Thread safety in Java web application data access class

A hobby project of mine is a Java web application. It's a simple web page with a form. The user fills out the form, submits, and is presented with some results. The data is coming over a JDBC Connection. When the user submits, I validate the input, build a "CREATE ALIAS" statement, a "SELECT" statement, and a "DROP ALIAS" statement. ...

Java: GUIs must be initialized in the EDT thread?

Hi, I'm Jason. I'm having a bit of a problem with the Substance look and feel (https://substance.dev.java.net/). My problem is more general. I've already got my GUI written and it works fine, but when I use a Substance Look-and-feel, it requires all GUI initialization to take place in the EDT thread (Event Dispatching Thread or somethin...

Why the name "monitor"?

I'm referring to monitors as described here: http://en.wikipedia.org/wiki/Monitor_(synchronization) None of the definitions here seem apropos: http://www.thefreedictionary.com/monitor So why are they called that? == Update == Thank you for the answers, everyone! I guess I was confused because I don't think of monitors usually as a...

Practical uses for threads

In your work, what specifically have you used threads for? (Please give a description of the application and how the thread helped/enhanced the application.) ...