multithreading

C# Interrupting native threads

Hello *, I am currently investigating how Thread.Interrupt plays together with P/Invoke or native calls. I have read in MSDN that it is not possible to abort (Thread.Abort) a thread which is in the native call (other use cases might apply as well). But I did not find any reference which states the same for native threads which are in Wa...

How to store data in MySql through multiple threads?

I have started five threads from main() function. I have written three funtions as follows: getConnectionToDatabase(); saveToDataBase(); closeConnection(); Now I want that main function should establish a connection to the database before starting those five threads by calling getConnectionToDataBase() so that each thread doesn't hav...

How to analyse a crash dump file using GDB

I have a server application running under Cent OS. The server answers many requests per second but it repeatedly crashes after each hour or so and creates a crash dump file. The situation is really bad and I need to find out the crash cause as soon as possible. I suspect that the problem is a concurrency problem but I'm not sure. I have...

C# - Locking a resource when obtained from dictionary

I have a Dictionary that tracks objects (ClientObject). Both the dictionary and ClientObject's are accessed by multiple threads. When I modify or read any object in this dictionary, I obtain a read or write lock on the dictionary using ReaderWriterLockSlim (rwl_clients) then obtain an exclusive lock on the actual object. I just wanted t...

How to run Valgrind in parallel with our process so its performance doesn't decrease too much?

Hi, I need to use Valgrind to detect any memory access violations made in a server application. The server creates many threads. I suspect that there is a racing condition that causes the server to crash every 1 hour or so. We used Valgrind to analyze its memory usage but the server process' speed decreased dramatically. The server's sp...

Unit testing a Java multi-threaded network app

I am writing a Java multi-threaded network application and having real difficulty coming up with a way to unit test the object which sends and receives communication from network clients. The object sends out a message to a number of clients and then waits for responses from the clients. As each client responds, a dashboard-style GUI i...

Error: Cross thread operation not valid

I am trying to access a form from a different thread to that on which the form was created, and finally ended up with an error: Cross thread operation not valid public static void MakeTopMost(Form form) { SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS); } I am passing a form which is running in another thread. ...

Debugging multitheaded programs

I have been a C programmer for many years and my favorite "debugger" has always been the printf() function - I only resort to visual studio's debugger when absolutely forced and so have never been very proficient in using it. Recently I have had to modify a program from C to C++ (although of course printf still works fine) and and parts ...

Debugger question

I have a bug I am chasing (I think its a deadlock). When I run the code it hangs without the debugger flagging an error, so after a while I try pressing the pause (break all) button. The debugger then reports "The process appears to be deadlocked...". I then can see that all the threads are held up at lines saying EnterCriticalSection ex...

How to handle exception in a background thread in a unit test?

I'm writing a unit test suite to test a TCP/IP communication library. As I'm using BeginAcceptClient and EndAcceptClient, the messages are received in a background thread. After a message is received, I perform some assertions on it, but if any assertion fails, the VSTestHost.exe crashes. I googled a bit and found out its the fact the...

Do threads clean-up after themselves in Win32/MFC and POSIX?

I am working on a multithreaded program using C++ and Boost. I am using a helper thread to eagerly initialize a resource asynchronously. If I detach the thread and all references to the thread go out of scope, have I leaked any resources? Or does the thread clean-up after itself (i.e. it's stack and any other system resources needed for ...

How to exit the entire application from a Python thread?

How can I exit my entire Python application from one of its threads? sys.exit() only terminates the thread in which it is called, so that is no help. I would not like to use an os.kill() solution, as this isn't very clean. ...

AutoResetEvent and COM Objects

I've noticed that AutoResetEvent completely freezes the message loop (sometimes) when in the middle of a WaitOne() call, effectively even blocking the signal message. IE: (UI) New thread spawned (UI) Code calls WaitOne(); timeout: 10s (T2) Thread opens device, calls Set() (UI) WaitOne blocks message loop (UI) WaitOne timeout elapsed, ...

How to parallelize threads in C pthreads

I have N threads and they have to do job on shared data. I am using following structure: int main(){ pthread_create(..., func, ...); } void *func(void *id){ lock; do_job; unlock; } My problem is that threads seem to work sequentially. How to actually make them parallel? ...

Purpose of ThreadLocal ?

Possible duplicate: When and how should I use a Threadlocal variable The purpose of ThreadLocal as given here states that the variable is local to any Thread accessing an object containing the ThreadLocal variable. What difference does it make, in having a ThreadLocal variable as a member of a class and then making it local to a Threa...

ThreadPool.SetMinThreads() can the completionPortThreads number be set to 0?

I want to set the minimum number of threads. I knoe the number of workerThreads I need but about the completionPortThreads what should be it's size (by dafault it is equal to the number of processors). can I set it to 0 or is it risky? when will it be used? ...

SQLite on iPhone - Techniques for tracking down multithreading-related bugs

Hey guys, I'm working with an Objective-C wrapper around SQLite that I didn't write, and documentation is sparse... It's not FMDB. The people writing this wrapper weren't aware of FMDB when writing this code. It seems that the code is suffering from a bug where database connections are being accessed from multiple threads -- which a...

How to program number of your threads in Delphi

I found this on the Dr Dobbs site today at http://www.ddj.com/hpc-high-performance-computing/220300055?pgno=3 It's a nice suggestion regarding thread implmentation. What is best way of achieving this with TThread in Delphi I wonder? Thanks Brian === From Dr Dobbs ============== Make multithreading configurable! The number of threads u...

ThreadLocal implementation

With reference to my earlier question, going a bit further, What are the disadvantages of using ThreadLocals as opposed to local variables How are they implemented Are session variables ThreadLocals Are there more examples of ThreadLocals used frequently ...

how to execute a piece of code only after all threads are done

Hi, I have a logging code which needs to be executed after all threads are executed. Thread t1 = new MyThread(); Thread t2 = new MyThread(); t1.run(); t2.run(); doLogging(); Is there any way to execute doLogging() only after both threads are done with their processing. Now that doLogging() is called as soon as t1, t2 are started. ...