What exactly is std::atomic?

Each instantiation and full specialization of std::atomic<> represents a type that different threads can simultaneously operate on (their instances), without raising undefined behavior: Objects of atomic types are the only C++ objects that are free from data races; that is, if one thread writes to an atomic object while another thread reads from it, the behavior is … Read more

What are atomic operations for newbies?

Pretty much, yes. “Atom” comes from greek “atomos” = “uncuttable”, and has been used in the sense “indivisible smallest unit” for a very long time (till physicists found that, in fact, there are smaller things than atoms). In concurrent programming, it means that there will be no context switch during it – nothing can affect the execution … Read more

What is the difference between a process and a thread?

Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces. I’m not sure what “hardware” vs “software” threads you might be referring to. Threads are an operating environment feature, rather than a CPU … Read more

Undefined reference to pthread_create in Linux

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/ But when I compile it on my machine (running Ubuntu Linux 9.04) I get the following error: This doesn’t make any sense to me, because the header includes pthread.h, which should have the pthread_create function. Any ideas what’s going wrong?

What’s a Pthread?

Threads are a generic concept. Wikipedia defines it as: In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by an operating system scheduler. A thread is a light-weight process. Pthreads or POSIX threads are one implementation of that concept used with C program on Unix. … Read more

What’s the difference between deadlock and livelock?

Taken from http://en.wikipedia.org/wiki/Deadlock: In concurrent computing, a deadlock is a state in which each member of a group of actions, is waiting for some other member to release a lock A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, … Read more

Python time.sleep() vs event.wait()

Using exit_flag.wait(timeout=DELAY) will be more responsive, because you’ll break out of the while loop instantly when exit_flag is set. With time.sleep, even after the event is set, you’re going to wait around in the time.sleep call until you’ve slept for DELAY seconds. In terms of implementation, Python 2.x and Python 3.x have very different behavior. … Read more