multithreading

What operations are thread-safe on std::map ?

Suppoes I have: stl::map<std::string, Foo> myMap; is the following function thread safe? myMap["xyz"] ? I.e. I want to have this giant read-only map that is shared among many threads; but I don't know if even searching it is thread safe. Thanks! EDIT: Everything is written to once first. Then after that, multiple threads read ...

sigprocmask() causing segfault

Are there any well known reasons for sigprocmask() to segfault when used in a multithreaded application? I have an application that creates multiple threads using clone(). I have determined that for some reason when I use sigprocmask it segfaults (not all the time though). From the backtrace() it also seems like the segfault is occuring...

Do I need to lock object when reading from it?

I am writing a program where there is an object shared by multiple threads: a. multiple write threads write to the object (all running the same function) b. a read thread which accesses the object every 5 seconds c. a read thread which accesses the object there is a user request It is obviously necessary to lock the object when writing ...

Set a timeout and get a result from a delegate thread

I've never had much to do with async callbacks and delegates before on WinForms (i.e., not AJAX) so I'm hoping someone can help me out with what I'm trying to do here. I'm logging into a third-party service over the web. The Login() method is of type Void. Because this can take up to 10 seconds (very occasionally longer) I want to do t...

WPF and cross thread operations

Hi, i have a small WPF application where im simulating movement detected by a sensor. I fake that movement occurs after 1 minute and it stops after 2 minutes. Below is my code: public event Action OnMotionDetected; public event Action OnMotionReset; private DateTime startTime = DateTime.Now; public MotionDetect...

Set value of label with C# Cross Threading

Hey, I need help with setting/changing the value of a label in my C# program whenever I try it an error occurs saying I need to cross thread it all. Can anyone write some code to help me with that? My code is: int number = 0; int repeats = Convert.ToInt32(textBox2.Text); while (number < repeats) { repeats++; label5.Text = "Reques...

Adding SoftReferences to the efficient and scalable result cache in "Java Concurrency in Practice"

I've been going through the Java Concurrency in Practice book. It is definitively a great reference. I'm trying to extend the last example of the efficient and scalable result set cache to incorporate soft references. The objects stored in my cache can grow rather large and I need some way for those objects to get garbage collected wh...

What SQL-Server lock level is suitable for insert?

I want to make almost 1000 inserts in a table in each second. And also each day I want to query all inserted rows just once at altogether. And I want to improve efficiency by multi-threading and connection-pooling. But i want to know which level of concurrency control is more suitable for me. The list of options for SQL-Server are in MSD...

How do you get a responsive GUI if your codebehind is running an infinte loop? PyQT

If you have a function consistently running an infinite loop in the background, how will your GUI ever be responsive? It is waiting for the loop to finish and this renders the interface useless. How is this solved in PyQT? ...

Good tools for Multi-threaded C++ debugging on MacOSX?

Hi! I recently switched form ubuntu to MacOSX. I also recently started heavily using multi threading. What good addons/alternatives are there to g++ for debugging multi-threaded apps on MacOSX? In particular, I'm interested in tools that let me "poke" around classes/structs; to follow pointers, expand members, show the value of member...

How to include boost::thread in your C++ project?

What do I need to do to include boost::thread in my project? I have copied the whole thread folder to my working path (I wish to be able to run this on several computers) and I get fatal error C1083: Cannot open include file: 'boost/thread/detail/platform.hpp': No such file or directory From the line #include "thread/thread...

Multithreading in... functional languages? (Prolog)

When my friend started learning Prolog in school, I made fun of him for learning a useless language. However, he's showed me some stuff I never even knew possible; I want to know where this technique comes from. The technique is this: permutation(List) :- isAMember(X, List), deleteFirstElement(X, List, Substring), % and so...

Cannot call COM object created from STAThread from oher STA threads

I am new to COM and trying to understand the difference between STA and MTA. I tried to create an example that would show that COM can manage calls to object created in STA that is not thread-safe. MyCalcServer class here is created using ATL Simple Object. The settings used are the same as in this article: Threading Model: Apartment...

call OpenGL functions from another thread

My application has two threads: A and B. The A is the main thread and B is my video thread. The video thread has an initialized OpenGL context where OpenGL functions work properly. However, when I call OpenGL functions from thread A, the function failed with a 1282 error (GL_INVALID_OPERATION) Is it possible to call OpenGL functions from...

How to find out which thread is locking a file in java?

I'm trying to delete a file that another thread within my program has previously worked with. I'm unable to delete the file but I'm not sure how to figure out which thread may be using the file. So how do I find out which thread is locking the file in java? ...

Looking for a good exercise to help me get better at Multithreading.

I think of myself as a pretty decent developer, however when it comes to multithreading I'm a total n00b. I mean the only multithreading I've done at work was the very basic stuff like spawning off multiple threads using the ThreadPool to do some background work. No synchronization was necessary, and there was never any need to create th...

Python: penalty for sleeping threads

Hello SO, this question relates to performance penalities that may or may not arise from having a large number of sleeping python threads on a webserver. Background: I am implementing an online shop using django/satchmo. A requirement is for delayed payment. The customer can reserve a product and allow a third party to pay for it at a l...

Abort a Thread started with Delegate.BeginInvoke

Disclaimer: I know that Thread.Abort is evil. I'm using it as a last resort since some I/O functions (e.g., File.Exists when used on a non-existing network share) block for a large amout of time and do not allow you to specify a timeout. Question: Is it possible to Abort (as in Thread.Abort) a worker thread started using Delegate.BeginI...

F#: Asynch and Tasks and PLINQ, oh my!

When F# comes out, I am going to have an embarrassment of riches in the asynchronous/parallel programming area. An answer to this question does a pretty good job of describing the differences between Tasks, Parallel LINQ, and Reactive Framework, but I was wondering how asynchronous workflows fit into the picture, exactly. Please correct...

implement multithreaded crawler

I would like to implement a mulithtreaded crawler using the single thread crawler code I have now. Basically I read the urls from a text file, take each one and crawl and parse it. I know how thread basics of creating a thread and assigning a process to it but not too sure how to implement in the following way: I need at least 3 threads...