multithreading

Opening multiple sessions simultaneously in NHibernate

I finally figured out what's wrong with my code, but I'm not sure how to fix it. I have some background processes running on a separate thread that perform some database maintenance tasks. Here's an exmple of what's happening: //Both processes share the same instance of ISessionFactory //but open separate ISessions //This is running on...

Future Protections in Managed Languages and Runtimes

In the future, will managed runtimes provide additional protections against subtle data corruption issues? Managed runtimes such as Java and the .NET CLR reduce or eliminate the possibility of many memory corruption bugs common in native languages like C#. Nonetheless, they are surprisingly not immune from all memory corruption problems...

Does Interlocked.CompareExchange use a memory barrier?

I'm reading Joe Duffy's post about Volatile reads and writes, and timeliness, and i'm trying to understand something about the last code sample in the post: while (Interlocked.CompareExchange(ref m_state, 1, 0) != 0) ; m_state = 0; while (Interlocked.CompareExchange(ref m_state, 1, 0) != 0) ; m_state = 0; … When the second CMPXCHG o...

How check if a task is already in python Queue?

Hello. I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, but if there ar...

Should an NSLock instance be "global"?

Should I make a single NSLock instance in the application delegate, to be used by all classes? Or is it advisable to have each class instantiate its own NSLock instance as needed? Would the locking work in the second case, if I, for example, had access to a managed object context that is spread across two view controllers? ...

Java network code not sending

I'm writing my first non-trivial Java app that uses: networking a GUI threads It's a IM program. When I send a message, the server doesn't output what it should. I'm sorry this description is so bad, but I don't know how to narrow the problem down further. public class MachatServer { //snip public static void sendMessage(i...

POSIX Threads: are pthreads_cond_wait() and others systemcalls?

The POSIX standard defines several routines for thread synchronization, based on concepts like mutexes and conditional variables. my question is now: are these (like e.g. pthreads_cond_init(), pthreads_mutex_init(), pthreads_mutex_lock()... and so on) system calls or just library calls? i know they are included via "pthread.h", but do t...

J2ME lcdui: Can I manipulate my GUI in a worker thread?

I'm just starting with J2ME and lcdui, and I'm looking at some sample code that calls methods on lcdui objects from a worker thread. In my experience with desktop GUI toolkits, this is usually forbidden - is lcdui different? Is it really OK to do this? (I've Googled for an answer to this question but not found anything - a link to a d...

Progress bar requirement as sufficient justification for multithreading via BackgroundWorker?

Taken as given that multi-threaded applications are debugging hell and should be avoided at all costs... Is the requirement to display of a progress bar a sufficient reason to enter multi-threaded land? Specifically, let's say a C# windows forms .NET 3.0 application needs to download a 100MB file. Is it right to multi-thread (via a Bac...

Threading for iframe elements in IE

Of the following, which are not run in the same thread as the current page in IE8? An iframe with the same domain as the current page. An iframe with a sub-domain of the current page's domain. An iframe with a super-domain of the current page's domain. An iframe with a completely different domain from the current page. I want to know...

Is this the right approach for a thread-safe Queue class?

Hey guys, I'm wondering if this is the right approach to writing a thread-safe queue in C++? template <class T> class Queue { public: Queue() {} void Push(T& a) { m_mutex.lock(); m_q.push_back(a); m_mutex.unlock(); } T& Pop() { m_mutex.lock(); T& temp = m_q.pop(); m_mutex.unlock(); return temp; } private...

How to wait for thread to finish with .NET?

I've never really used threading before in C# where I need to have two threads, as well as the main UI thread. Basically, I have the following. public void StartTheActions() { //Starting thread 1.... Thread t1 = new Thread(new ThreadStart(action1)); t1.Start(); //Now, I want for the main thread (which is calling StartTheActions() ) to ...

Are there any algorithms for efficient allocation and usage of UI threads for use with WPF?

WPF utilizes a single thread to dispatch events via the windows event pump. When each control is created, it is associated with a thread and consequently all activities associated with that control need to occur on that thread. We've got an application that has a large number of top-level windows, each with a host of controls within th...

C# exception: Key is not present in the dictionary

Hi there. I got a little problem. Sometimes, when I try to call the following code, the remove methods throw an exception with the message "the key is not present in the dictionary". private Dictionary<IPAddress, ARPHostEntry> dIPHostTable; private Dictionary<MACAddress, ARPHostEntry> dMACHostTable; public HostTable() { dIPHostTab...

Can I use a .net control parent class to enable/disable it?

I need to write a delegate for a multi-threaded program that will enable/disable a variety of controls. It seems logical that using one handler for all controls would be the best choice, but I'm not even sure this is possible in .net and if so how to implement. ...

Is there any comprehensive overview somewhere that discusses all the different types of threads?

Is there any comprehensive overview somewhere that discusses all the different types of threads and what their relationship is with the OS and the scheduler? I've heard so much contradicting information about whether you want certain types of threads, or whether thread pooling is a performance gain or a performance hit, or that threads a...

Is the Python GIL really per interpreter?

I often see people talking that the GIL is per Python Interpreter (even here on stackoverflow). But what I see in the source code it seems to be that the GIL is a global variable and therefore there is one GIL for all Interpreters in each python process. I know they did this because there is no interpreter object passed around like lua ...

Do atomic operations work the same across processes as they do across threads?

Obviously, atomic operations make sure that different threads don't clobber a value. But is this still true across processes, when using shared memory? Even if the processes happen to be scheduled by the OS to run on different cores? Or across different distinct CPUs? Edit: Also, if it's not safe, is it not safe even on an operating sys...

When are lock free data structures less performant than mutual exclusion (mutexes)?

I read somewhere (can't find the page anymore) that lock free data structures are more efficient "for certain workloads" which seems to imply that sometimes they're actually slower or the gain from them can be zero in some situations. Taking the ~100 cycle hit of a lock instruction to do an atomic op sounds plenty faster to me than going...

Do atomic operations become slower as more CPUs are added?

x86 and other architectures provide special atomic instructions (lock, cmpxchg, etc.) that allow you to write 'lock free' data structures. But as more and more cores are added, it seems as though the work these instructions will actually have to do behind the scenes will grow (at least to maintain cache coherency?). If an atomic add take...