Questions tagged [thread-safety]

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).

Thread Safety

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).

Main approaches to thread safety include re-entrancy, thread-local storage, mutual exclusion (locking), atomic operations, and immutable objects.

Resources

9311 questions
5
votes
1 answer

How to Start a Java MVC Application With a Swing GUI

Let us assume we have a simple Java MVC Application with the classes Model, View and Controller. The View class directly inherits from JFrame. As in a classic MVC setup, the view has a reference to the model and the controller has a reference to the…
Simon
  • 4,103
  • 7
  • 28
  • 53
5
votes
2 answers

Is scandir really thread safe?

In the UNIX® System Threads Reference, under the heading of "Thread-safety" is a list of functions are "not guaranteed to be thread-safe on all UNIX systems." The function scandir() is absent from this list, while readdir() appears on the list. …
Mike Godin
  • 3,727
  • 3
  • 27
  • 29
5
votes
3 answers

Are different threads on different instances of JavascriptSerializer or JavascriptDeserializer thread safe

I am looking for a definitive answer here. According to the documentation the public static methods of JavascriptSerializer are thread safe but the non-static methods are not. Is it guaranteed that for the public non-static methods of this class…
user334911
5
votes
3 answers

Are there any thread-safe graph libraries for C++?

Basically I am looking for a graph library that would have fine-grained locking around graph operations, so that different threads touching different parts of the graph could alter it simultaneously, and competing modifications could be blocked. I…
drpepper
  • 462
  • 1
  • 5
  • 16
5
votes
1 answer

Are ANTLR parsers for Java thread safe?

Is an ANTLR (v3.2) generated Java parser thread safe? For example, in a servlet request handler, can I reuse the same parser instance to parse a request body? The requests may come in on different threads, so parsing must be done in a thread safe…
djb
  • 4,930
  • 1
  • 34
  • 37
5
votes
1 answer

Thread safety of const reference return of const method

Consider this class: #include class A { private: std::vector m_vector; public: void insertElement(int i) { m_vector.push_back(i); } const std::vector& getVectorRef() const { return m_vector; …
Juergen
  • 3,489
  • 6
  • 35
  • 59
5
votes
2 answers

what does it mean by "Immutable strings are threadsafe"

I have recently started to read up on mutable and immutable objects in C# and the constant thing i find wherever i read is hat being immutable makes things threadsafe and useful when used as keys in hashtables but what i dont understand is as far as…
5
votes
1 answer

OpenMP, writing to distinct array elements in parallel

In OpenMP can you write to distinct elements of that array in parallel? Here's a simple test program: #include #include int main(){ const int n=100; int squares[n]; // Can we write to distinct array elements…
Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
5
votes
1 answer

C++ Boost read_json crash and I had #define BOOST_SPIRIT_THREADSAFE

Recently other people upgraded our boost library, now I see this coredump when a read_json function is called heavily. Never seen this before. And I have #define BOOST_SPIRIT_THREADSAFE in the code, that's why this didn't happen before. Really need…
5
votes
3 answers

Are the SetValue/GetValue methods of System.Array thread-safe?

We had a little discussion in the office, and got no documented answer: Is System.Array.SetValue thread safe? using System; using System.Text; using System.Threading; namespace MyApp { class Program { private static readonly…
Ron Klein
  • 9,178
  • 9
  • 55
  • 88
5
votes
1 answer

Is it thread-safe to use QueryDsl query entities as dao fields

Is it thread-safe to use QueryDsl query entities like the following public class MyDaoImpl implements MyDao { private static final QEntity entity = QEntity.entity; public List entities() { return new…
RJo
  • 15,631
  • 5
  • 32
  • 63
5
votes
5 answers

Thread safe implementation for Hash Map

First, I'll describe what I want and then I'll elaborate on the possibilities I am considering. I don't know which is the best so I want some help. I have a hash map on which I do read and write operations from a Servlet. Now, since this Servlet is…
pratnala
  • 3,723
  • 7
  • 35
  • 58
5
votes
1 answer

pipe and thread safety

I create a pipe and a thread in my linux C program. So there are 2 threads: main thread and the second thread. The second thread writes bytes into the pipe. In the main thread, I register an EV_READ event(libevent, it is similar to read event in…
misteryes
  • 2,167
  • 4
  • 32
  • 58
5
votes
1 answer

Thread synchronization based upon an id

I need a way to allow only one thread to modify data related to a service ticket. More than one thread may be attempting to modify the ticket data at the same time. Below is a simplified version of my approach. Is there a better way to do this?…
Jeff Miller
  • 1,424
  • 1
  • 10
  • 19
5
votes
3 answers

Is there a list of thread-safe classes in Java?

I am trying to apply the lessons from reading Java Concurrency In Practice with regards to declaring whether classes that I write are either thread-safe or that they contain unsynchronised mutable state. I think this is a good idea because it…
Matt
  • 557
  • 9
  • 17
1 2 3
99
100