multithreading

using statement vs try finally

I've got a bunch of properties which I am going to use read/write locks on. I can implement them either with a try finally or a using clause. In the try finally I would acquire the lock before the try, and ralease in the finally. In the using clause, I would create a class which acquires the lock in its constructor, and releases in its...

C++ multithreading tutorial

Hello all, does anyone know a good tutorial on working with (programming) threads in Visusal Studio 2005? Not MFC related, just native C++ (no .NET) Thanks ...

How do I use PostThreadMessage to close internet explore from c++

Hi Im trying to start iexplore.exe let it run for 5 seconds and then close it again. iexplore opens just fine however it doest close when i call the PostThreadMessage can any one see what im doing wrong here is the code: CString IEPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";//GetIEPath(); //IEPath += ' ' + url; std::st...

What is the rationale of SwingWorker?

For what I can read, it is used to dispatch a new thread in a swing app to perform some "background" work, but what's the benefit from using this rather than a "normal" thread? Is not the same using a new Thread and when it finish invoke some GUI method using SwingUtilities.invokeLater?... What am I missing here? http://en.wikipedia....

.Net Compact Framework - can I prevent garbage collector to stop some of my threads ?

Hi, I wonder if it is possible in a Compact Framework application to prevent the garbage collector to unconditionally stop at least one of the threads, or if it is possible to block GC collects at least in some portions of the code. I think it has to deal with setting real time priorities, but I found a lot of advices against doing it.....

Checking for null before event dispatching... thread safe?

Something that confuses me, but has never caused any problems... the recommended way to dispatch an event is as follows: public event EventHandler SomeEvent; ... { .... if(SomeEvent!=null)SomeEvent(); } In a multi-threaded environment, how does this code guarantee that another thread will not alter the invocation list of SomeE...

Erlang JInterface - is OtpMBox thread-safe?

In my Java program, I create a OtpNode and a "named" OtpMBox. Whenever a message is received via this mbox, some time-consuming operation needs to be performed after which a reply message is sent back. Since this operation is time-consuming, subsequent messages sent to the mbox won't be processed immediately. So I want to use Java thre...

How to get non-current thread's stacktrace?

It is possible to get stacktrace using System.Diagnostics.StackTrace, but thread has to be suspended. Suspend and Resume function are obsolete, so I expect that better way exists. ...

Is there a slim reader/writer lock for .NET 2.0?

I've looked at the ReaderWriterLock in .NET 2.0 and the ReaderWriterLockSlim in .NET 3.5, and the slim version doesn't use kernel objects for the locking. For my context, which can potentially generate a large (but not huge) amount of objects, this sounds better. But the code I write needs to be used in both .NET 2.0 and 3.5 during a tr...

Can I be sure that the code I write is always executed in the same thread?

I normally work on single threaded applications and have generally never really bothered with dealing with threads. My understanding of how things work - which certainly, may be wrong - is that as long as we're always dealing with single threaded code (i.e. no forks or anything like that) it will always be executed in the same thread. I...

JDBC: Can I share a connection in a multithreading app, and enjoy nice transactions?

It seems like the classical way to handle transactions with JDBC is to set auto-commit to false. This creates a new transaction, and each call to commit marks the beginning the next transactions. On multithreading app, I understand that it is common practice to open a new connection for each thread. I am writing a RMI based multi-client...

How to make a Java thread wait for another thread's output?

Hello, I'm making a Java application with an application-logic-thread and a database-access-thread. Both of them persist for the entire lifetime of the application. However, I need to make sure that the app thread waits until the db thread is ready (currently determined by calling dbthread.isReady()). I wouldn't mind if app thread block...

when does a thread go out of scope?

I've written a program that counts lines, words, and characters in a text: it does this with threads. It works great sometimes, but not so great other times. What ends up happening is the variables pointing to the number of words and characters counted sometimes come up short and sometimes don't. It seems to me that the threads are some...

SQL Server cannot obtain a LOCK resource at this time - What to do?

I have a stored procedure on SQL Server 2005 doing a Serializable Transaction. Inside this transaction, it selects a table with rowlock. At the end of the procedure, after rollback/commit, it sets the transaction isolation level to Read Commited. This procedure is running, different processes have concurrent access controlled by these c...

Why are event-based network applications inherently faster than threaded ones?

We've all read the benchmarks and know the facts - event-based asynchronous network servers are faster than their threaded counterparts. Think lighttpd or Zeus vs. Apache or IIS. Why is that? ...

How to automatically copy data to new RMI threads ?

Hello, I am adapting a little rmi client-server application. I have written several things : HelloInterface -> A Hello World interface for RMI Server -> The server app' Client -> The client app' Nothing special, but... I have put my hands in a new RMISecurityManager, which calls a JNI method and checks the permission for a separate us...

Interacting with UI threads in Java/J2ME

I'm writing a J2ME application. One of the pieces is something that polls the contents of a directory periodically, and, if there are any new things, paints them on the screen. I've done this by having the UI form launch a polling thread with a pointer back to itself, and when the polling thread finds something it calls back to the for...

Raising Events from a thread safely

I am having some problems with events being raised from the non-UI thread, in that i dont wish to have to handle the If me.invokerequired on every event handler added to the thread in Form1. I am sure i have read somewhere how to use a delegate event (on SO) but i am unable to find it. Public Class Form1 Private WithEvents _to As ...

What is the best approach to handling exceptions thrown in a separate thread?

I am working on a J2ME project that spawns worker threads for numerous tasks such as downloading HTTP content. The basic thread layout is similar to most java apps--there is a main UI thread and worker threads spawned to do stuff behind the scenes. My question is what is the best way to handle exceptions that occur in the worker threads?...

How do I count bytecodes in Python so I can modify sys.setcheckinterval appropriately

I have a port scanning application that uses work queues and threads, it uses simple TCP connections and spends a lot of time waiting for packets to come back (up to half a second). Thus the threads don't need to fully execute (i.e. first half sends a packet, context switch, does stuff, comes back to thread which has network data waiting...