multithreading

What happens if I lock an object while another thread use that variable?

I am not sure how lock works. What happens if I have a List<T> list and 2 threads ? What happens if thread1 start running first and enumerate that list foreach(T t in list) { // code } and in the same time, but after thread1 has started, thread2 will lock the list lock(list) { // code } I use ThreadPool do to some processing a...

Is java.sql.Connection thread safe?

To rephrase the question: should I avoid sharing instances of classes which implement java.sql.Connection between different threads? ...

Thread safe DateTime update using Interlocked.*

Can I use an Interlocked.* synchronization method to update a DateTime variable? I wish to maintain a last-touch time stamp in memory. Multiple http threads will update the last touch DateTime variable. I appreciate that DateTime variables are value types that are replaced rather than updated. The best I can come up with is to hold th...

Problem with Random and Threads in .NET

I'm having trouble with the Random class in .NET, I'm implementing a threaded collection which is working fine, except for one smaller detail. The collection is a Skip list and those of you familiar with it know that for every node inserted I need to generate a new height that is <= CurrentMaxHeight+1, here's the code that I'm using to d...

Php multithread

Php, isn't really made for multithread but do you have any workarround to deal with threads in php. ...

Switch to other thread while debugging session in Visual C# Express 2008

I have app that uses two threads: one thread for regular application work and another that does some background processing. When I debug my app and have a error message displayed I click pause to get to the line when this error ocurred. But unfortunately I'm redirected to current line of the second background thread. My question is: ho...

the fastest way to create checksum for large files in python

hi, i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on Windows XP Pro 64bit machine. i suspect i've hit the 32bit limitation here? using hashlib...

Java Multi-Threading Beginner Questions

I am working on a scientific application that has readily separable parts that can proceed in parallel. So, I've written those parts to each run as independent threads, though not for what appears to be the standard reason for separating things into threads (i.e., not blocking some quit command or the like). A few questions: Does this...

C Threaded Programming - Incrementing a shared variable

Hey guys...so I'm trying to brush up on my C threads and a question I've found is this: Given a global variable int x = 0; implement the function void useless(int n) which creates n threads which in a loop increase x by 1, each thread terminates when x reaches 100. I just don't have a handle on threads and need a solid example to base...

Changing visibility in WPF with a timer

Hi, I have an application where I need to switch visibility of some controls using a timer. Each 5 seconds, some controls disappears while some other appears. When I used a timer, it says that cannot change the visibility because the timer thread is not the owner of the control. How can we bypass that? Tks ...

Image retriever in a thread

Hi ! I'm trying to make an image retriever to work with a list. The list contains items of type (TItem) for example. TItem has some properties like title, image and imageURL. There is a thread with the list that scan all items and try to retrieve the image of each item by using the imageURL of each item. The thread that retrieve the ...

NSRunAlertPanel() outside of the main thread?

I've stumbled upon a problem in the application I'm developing using cocoa. I need to do some processing, and I'm doing it on a separate thread. I'm doing this so I can display the progress using a NSProgressIndicator and not hang the main thread. (The user can cancel the execution if he/she wants). It's almost working perfectly, But th...

Threads and CoreGraphics

I have a background thread that uses CGBitmapContextCreate to do some drawing to a memory buffer. I believe this is causing random EXEC_BAD_ACCESS exceptions. Keyword is random. I believe it may be my lack of understanding of CG thread safety. That is a guess, but I've checked quite thoroughly via line by line debug outputs and the bug ...

.Net Timeouts: WaitForSingleObject vs Timer

I'm implementing a timeout on an asynchronous operation (a series of network IOs), and I'm not sure which is 'better' (from a allocations / performance) perspective: creating an EventWaitHandle and using RegisterWaitForSingleObject, or just creating a Timer and using its Tick. In my specific case the EventWaitHandle is lazy-created, but...

Multithreading libraries for Objective-C

Excluding Cocoa (and its NSThread), what multithreading libraries would you recommend? The application's engine must run on multiple platforms (Windows, Linux, MacOS, iPhone), and be multithreaded. Abstracting the library to compile against platform-specific MT libraries is possible, but incurs an extra layer of overhead and complexity...

Using uncaughtExceptionHandler effectively.

I got to know about this Java 1.5 capability recently and I developed a sample code to use this. My objective is to restart the thread when it gets dead due to an uncaught exception. public class ThreadManager { public static void main(String[] args) throws InterruptedException { startThread(); } public static void st...

What is the difference between synchronized and static synchronized?

For a travel booking web application, where there are 100 concurrent users logged in, should ticket booking and generating an "E-Ticket Number" be implemented by a "synchronized" or a "static synchronized" method? ...

Running nUnit tests in a multithreaded fashion

Is it possible to run nunit tests in a multithreaded fashion? Is there any runner which can provide this? Before someone jump on "unit test" concept, let me explain: These are not unit tests we are using nunit for functional / integration testing as well, and some of those tests are incredibly slow, got lots of wait state. Therefore mul...

Android:android.view.ViewRoot$CalledFromWrongThreadException - How to solve the problem?

Hi, An application I am currently developing is communicating with the server and the communication process runs in its own thread. There are asynchronous calls - for example login() and onLoginResponse(). login() is called in the main activity and the response is handled in main activity as well (onLoginResponse()). In onLoginResponse...

Is there a pattern for this queueing system, and example Java code?

I have a component that I wish to write and it's the kind of thing that feels like a common pattern. I was hoping to find the common name for the pattern if there is one, and examples of how to go about implementing it. I have a service that queues requests and processes them one at a time. I have a number of client threads which make t...