multithreading

Blackberry application hangs and freezes on UI modification

I've written a Blackberry appliation with the Blackberry JDE, running on a 9000 simulator. I tested it a week or so ago and loaded it on a Blackberry 9000 phone, and everything worked just fine. Sometime between then and now, though, something went wrong. My code does the whole moving arrow "loading things from the internet" or whatever...

(Python) Passing a threading.Thread object through a function?

I have a timer function: # This is a class that schedules tasks. It will call it's ring() funtion # when the timer starts, and call it's running() function when within the # time limit, and call it's over() function when the time is up. # This class uses SYSTEM time. import time, threading import settings from object import Object c...

One-off System.Threading.Timer state not finalized until program exit.

I may be doing something dumb, in which case I apologize. I'm working with the System.Threading.Timer class, and am setting on-off timers, using a state object to pass control information. Everything is work as I expected, except that the state object doesn't get finalized until the program exits. This example shows what I mean. class S...

How to handle same socket in different threads?

I am trying to handle socket in different threads creating runtime failure. See following code. void MySocket::Lock() { m_LockCount++; if( m_LockCount ) { CSocket::Create( 8080 ); } } void MySocket::Unlock() { m_LockCount--; if( !m_LockCount ) { CSocket::Close(); } } I am calling Lock() fro...

What is a worker thread and its difference from a thread which I create?

I create a thread by Thread newThread= new Thread(DoSomeWork); . . . private void DoSomeWork() { } Is this any different from a Worker thread? If its is..which is better and when should I use a worker thread? My application needs to have lots of thread doing monitoring, refreshing.. ...

Thread Safe Access to Data Shared Between Objects

I'm something of an intermediate programmer, but relatively a novice to multi-threading. At the moment, I'm working on an application with a structure similar to the following: class Client { public: Client(); private: // These are all initialised/populated in the constrcutor. std::vector<struct clientInfo>...

References for learning to write multi-threaded application in C#?

One of library I am working on, requires support of asynchronous operations. This library communicates with external devices using serial port (RS232) which can be quiet slow. I went through many MSDN articles but I am not feeling confident. I think if you are 100% sure that your multi-threaded application is thread-safe, then it might ...

Premature string destruction and how to avoid it?

Hi! I'm using Delphi 2009 and get some strange errors using the following code segment: var Str : AnsiString; CharPtr : PAnsiChar; ... CharPtr := PAnsiChar (Str); ExecuteInBackgroundThread ( procedure begin DoSomething (CharPtr); end); I'm guessing that the string is destructed when falling out of scope and under some ...

What is the simplest way to do background tasks in Windows.Forms?

Background tasks being stuff that involves network I/O, disk I/O, or other long-running tasks that may or may not take place over a network. It will often intermix with code that updates the GUI, which needs to be running on another thread, the GUI thread. Simple meaning that when opening a Form.cs file, the source code is as easy or e...

Do I need a mutex for reading?

I have a class that has a state (a simple enum) and that is accessed from two threads. For changing state I use a mutex (boost::mutex). Is it safe to check the state (e.g. compare state_ == ESTABLISHED) or do I have to use the mutex in this case too? In other words do I need the mutex when I just want to read a variable which could be co...

Constructing a C++ object (the MFC CRecordset) thread-safely

We're trying to build a class that provides the MFC CRecordset (or, really, the CODBCRecordset class) thread safety. Everything actually seem to work out pretty well for the various functions like opening and moving through the recordset (we enclose these calls with critical sections), however, one problem remains, a problem that seems t...

Good book about threading in .Net

Hello people!!! Can someone recommend me a good book about threading in .Net, im using the 3.5 framework and working with Visual Basic. Thanks in advance ...

WebSphere MQ Message Listener Threads

Hi, I am trying to figure out how WSMQ handles message listeners and threads. If I have one instance of a message listener, and have many queues, does each listener create a new thread for each queue? Or will there be one thread for the listener? Any insight will greatly help, thank you. ...

A way to destroy "thread" class

Here is a skeleton of my thread class: class MyThread { public: virutal ~MyThread(); // will start thread with svc() as thread entry point void start() = 0; // derive class will specialize what the thread should do virtual void svc() = 0; }; Somewhere in code I create an instance of MyThread an...

CopyOnWriteArrayList throwing CurrentModificationException

I'm occasionally getting a ConcurrentModificationException when I iterate over a list. A Google search informs me that it's probably because I'm altering that list in another thread while iterating over it and that to make this problem go away I should use java.util.concurrent.CopyOnWriteArrayList.... ... except I already am. Apparent...

C# Thread in Thread: how to get SynchronizationContext.Current ?

I have a WindowsForms application wich has SynchronizationContext.Current not null But from that WindowsForms app I create a new Thread called thread1 From thread1 I create another Thread called thread2 When I try to POST methods from thread2 in thread1 using SynchronizationContext.Current, will fail because SynchronizationContext.Curren...

Optimizing independent foreach iterations in .NET3.5

Let's say I have foreach(int x in xs[]) // xs is an array of int { x++; } Each time through the foreach is independent of the others. Is there a quick way to instruct the CLR to do each on a seperate thread or speed it up by natively parallelising it? Maybe it already knows to do this. I know you I could create threads and start t...

Java thread: 'join' froze my program

Hi all, My program looked like this: class Prog { BufferedImage offscreen; KindOfDatabase db; MyThread thread; class MyThread extends Thread { volatile boolean abort=false; long lastUpdated; public void run() { try { KindOfCursor c = db.iterator(); while(c.getNext()) ...

Android: HTTP/JSON communication within application or separate thread?

I've an application which receives and sends data (JSON) from/to a HTTP server via HTTP POST requests. There is not really any payload except of a few strings, so I'm wondering if it would make sense to build this whole HTTP communication as an Android Service or just to create a separate thread within my application? ...

How to localize string resource lookups from all threads in an application?

The recommended best practice is to set the current culture of the application's thread to enable resource look ups to use the correct language. Unfortunately, this does not set the culture for any other threads. This is especially a problem for thread-pool threads. The question is: how is it possible to set enable string resource lo...