A piece of code is thread-safe if it only manipulates data structures in a way that allows consistent execution of this code by multiple threads. A code may be thread safe, conditionally safe (mutual exclusion required) or unsafe (can only be safely used by one thread).

644
votes
11answers
406k views

Collection was modified; enumeration operation may not execute

I can't get to the bottom of this error, because when the debugger is attached, it does not seem to occur. Below is the code.This is a WCF server in a Windows service. The method NotifySubscribers ...
160
votes
9answers
106k views

Automating the InvokeRequired code pattern

I have become painfully aware of just how often one needs to write the following code pattern in event-driven GUI code, whereprivate void DoGUISwitch() {// cruisin for a bruisin' through ...
168
votes
2answers
41k views

Is local static variable initialization thread-safe in C++11? [duplicate]

I know this is an often asked question, but as there are so many variants, I'd like to re-state it, and hopefully have an answer reflecting the current state. Something likeLogger& g_logger() {...
19
votes
2answers
6k views

Are global variables thread safe in flask?

In my app the state of a common object is changed by making requests, and the response depends on the state.class SomeObj():def __init__(self, param):self.param=paramdef query(...
170
votes
9answers
105k views

Why is Java's SimpleDateFormat not thread-safe? [duplicate]

Please tell with a code example why is SimpleDateFormat not threadsafe. What is the problem in this class?Is The problem with format function of SimpleDateFormat? Please give a code which ...
105
votes
8answers
63k views

What's the best way of implementing a thread-safe Dictionary?

I was able to implement a thread-safe Dictionary in C# by deriving from IDictionary and defining a private SyncRoot object:public class SafeDictionary<TKey, TValue>: IDictionary<TKey, ...
639
votes
4answers
279k views

What is thread safe or non-thread safe in PHP?

I saw different binaries for PHP, like non-thread or thread safe? What does this mean? What is the difference between these packages?
347
votes
8answers
198k views

How does lock work exactly?

I see that for using objects which are not thread safe we wrap the code with a lock like this:private static readonly Object obj=new Object();lock (obj){// thread unsafe code}So what ...
48
votes
4answers
34k views

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?
60
votes
10answers
47k views

Is malloc thread-safe?

Is the malloc() function re-entrant?
73
votes
2answers
36k views

Difference between -pthread and -lpthread while compiling

What is the difference between gcc -pthread and gcc -lpthread which is used while compiling multithreaded programs?
148
votes
7answers
59k views

What exactly is a reentrant function?

Most of the times, the definition of reentrance is quoted from Wikipedia:A computer program or routine isdescribed as reentrant if it can besafely called again before itsprevious ...
107
votes
1answer
12k views

Does const mean thread-safe in C++11?

I hear that const means thread-safe in C++11. Is that true?Does that mean const is now the equivalent of Java's synchronized?Are they running out of keywords?
20
votes
1answer
9k views

Redirecting stdout and stderr to a PyQt4 QTextEdit from a secondary thread

Stack overflow. Once again, I come to you in a time of dire need, teetering precariously on the brink of insanity. This question - as may be evident from the title - is an amalgamation of several ...
11
votes
5answers
2k views

Thread safe multitons in Java

Given the following multiton:public class Multiton {private static final Multiton[] instances=new Multiton[...];private Multiton(...) {//...}public static ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,