multithreading

When to use threading against a scheduled task/web methods

These two may look like they have no correlation but bear with me! In a previous version of the software I develop/maintain there was a web app sitting on top of a web service. There was a scheduled task that run every hour called one of the web methods to carry out some tasks. In the new architecture we now have a web application pr...

How to wait for a background thread/operation to complete in WPF UI code?

e.g. in Winforms I'd write... // on UI Thread BackgroundWorker workerThread = new BackgroundWorker(); workerThread.DoWork += new DoWorkEventHandler(LoadChildren); workerThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(OnLoadChildrenCompleted); while (workerThread.IsBusy) { Application.DoEvents();...

Cross thread communication in Delphi

Is there any documentation on cross thread communication in Delphi? How can I send message to the thread that doesn't have a window? ...

Is there any scenario where an application instance runs across multiple computers?

We know that a single application instance can use multiple cores and even multiple physical processors. With cloud and cluster computing, or other special scenario, I don't know if a single stance can run across multiple computers, or across multiple OS instances. This is important for me because, besides being considered as bad progra...

Re-creating threading and concurrency knowledge in increasingly popular languages

I am primarily a Java developer, and I've been reading a lot of in-depth work on threads and concurrency. Many very smart people (Doug Lea, Brian Goetz, etc) have authored books on these topics and made contributions to new concurrency libraries for Java. As I start to learn more about Python, Ruby, and other languages, I'm wondering: ...

Does UIActivityIndicator require manual threading on iPhone

I am running creating an iPhone application which performs a costly operation and I wanted to create an activityIndicator to let the user know the application has not frozen. The operation is performed entirely in one event call... so there is no chance for the UI framework to receive control to actually display and animate this indicat...

Is mixing WPF, LinqToSql and multiple threads a bad idea?

My situation is roughly similar to this guy except that I don't need change notifications right now I have a WPF App displaying a hierarchy. The children for each node are retrieved using a LinqToSql query. The app works perfectly when there is one thread. Now I'd like to make things a bit faster.. by loading children asynchronously. F...

Ways for lazy "run once" initialization in Java with override from unit tests

I'm looking for a piece of code which behaves a bit like a singleton but isn't (because singleton's are bad :) What I'm looking for must meet these goals: Thread safe Simple (Understand & use, i.e. few lines of code. Library calls are OK) Fast Not a singleton; for tests, it must be possible to overwrite the value (and reset it after th...

_lsprof.c profiler behaviour towards python multi-threading

Hello! This is a question about Python native c file _lsprof. How does _lsprof.profile() profiler counts total time spent on a function f in a multi-threaded program if the execution of f is interrupted by another thread? For example: def f(): linef1 linef2 linef3 def g(): lineg1 lineg2 And at the execution we have, f...

Why does Paramiko hang if you use it while loading a module?!

Put the following into a file hello.py (and easy_install paramiko if you haven't got it): hostname,username,password='fill','these','in' import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(hostname=hostname, username=username, password=password) i,o,e = c.exec_command('ls /') print(...

Are incrementers / decrementers (var++, var--) etc thread safe?

Inspired by this question: http://stackoverflow.com/questions/443423/in-complexity-analysis-why-is-considered-to-be-2-operations Take the following psuedo code: class test { int _counter; void Increment() { _counter++; } } Would this be considered thread safe on an x86 architechure? Further more are the Inc / Dec as...

Log4Net works in main thread but not in created thread

In VS2008, C#, I've created a unit test (VS unit test) that calls some code which in turn calls Log4Net and logs some information. This works. If I create a thread in the unit test to call the same code I'm getting "Failed to parse config file" exception from Log4Net. Any ideas why it would not be able to parse the config file from the...

How to prevent deadlocks in the following C# code?

The following C# class is used in a multithreaded enviroment. I removed very much of the actual code. The problem occurs when calling MethodA and MethodB almost simultaneously. The order of the lock in the IsDepleted property doesn't solves the problem. Removing lock(WaitingQueue) from the IsDepleted property solves the deadlock, but thi...

C# thread pool limiting threads

Alright...I've given the site a fair search and have read over many posts about this topic. I found this question: http://stackoverflow.com/questions/435668/code-for-a-simple-thread-pool-in-c especially helpful. However, as it always seems, what I need varies slightly. I have looked over the MSDN example and adapted it to my needs some...

Multithreading and concurency with C#

In a Windows Form window, multiple events can trigger an asynchronous method. This method downloads a file and caches it. My problem is that I want that method to be executed once. In other words, I want to prevent the file to be downloaded multiple times. If the method downloading the file is triggered twice, I want the second call to...

PostMessage occasionally loses a message

I wrote a multi-threaded windows application where thread: A – is a windows form that handles user interaction and process the data from B. B – occasionally generates data and passes it two A. A thread safe queue is used to pass the data from thread B to A. The enqueue and dequeue functions are guarded using a windows critica...

Sample Problems for Multithreading Practice

I'm about to tackle what I see as a hard problem, I think. I need to multi-thread a pipeline of producers and consumers. So I want to start small. What are some practice problems, in varying levels of difficulty, that would be good for multi-threading practice? (And not contrived, impractical examples you see in books not dedicated t...

Triggering a method to run in a separate thread

I want to know how I can run a method in a separate thread? Class & Method references. Thanks. ...

Locking HttpRuntime.Cache for lazy loading

We have a website running .NET 2.0 and have started using the ASP.Net HttpRuntime.Cache to store the results of frequent data lookups to cut down our database access. Snippet: lock (locker) { if (HttpRuntime.Cache[cacheKey] == null) { HttpRuntime.Cache.Insert(cacheKey, GetSomeDataToCache(), null, DateTime.Today.AddDa...

Multithreaded Resource Access - Where Do I Put My Locks?

I have threaded code where each thread needs to write to the same file. To prevent concurrency issues, I am using a Lock object. My question is whether I am using the Lock correctly. If I set the lock from within each thread, is that lock global or only specific to that specific thread? Basically, should I create a Lock first and pas...