race-condition

Why is `$@` untrustworthy?

为君一笑 提交于 2019-11-29 17:38:21
问题 I seem to recall that it is not safe to trust the value of $@ after an eval . Something about a signal handler having a chance to set $@ before you see it or something. I am also too tired and lazy right now to track down the real reason. So, why is it not safe to trust $@ ? 回答1: The Try::Tiny perldoc has the definitive discussion of the trouble with $@ : There are a number of issues with eval. Clobbering $@ When you run an eval block and it succeeds, $@ will be cleared, potentially

Race condition: Min and Max range of an integer

北慕城南 提交于 2019-11-29 10:44:15
问题 I was recently asked this question in an interview. Given the following code, what will be the min and max possible value of the static integer num ? import java.util.ArrayList; import java.util.List; public class ThreadTest { private static int num = 0; public static void foo() { for (int i = 0; i < 5; i++) { num++; } } public static void main(String[] args) throws Exception{ List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < 5; i++) { Thread thread = new Thread(new Task());

How can barriers be destroyable as soon as pthread_barrier_wait returns?

筅森魡賤 提交于 2019-11-29 06:13:23
This question is based on: When is it safe to destroy a pthread barrier? and the recent glibc bug report: http://sourceware.org/bugzilla/show_bug.cgi?id=12674 I'm not sure about the semaphores issue reported in glibc, but presumably it's supposed to be valid to destroy a barrier as soon as pthread_barrier_wait returns, as per the above linked question. (Normally, the thread that got PTHREAD_BARRIER_SERIAL_THREAD , or a "special" thread that already considered itself "responsible" for the barrier object, would be the one to destroy it.) The main use case I can think of is when a barrier is used

Chrome Extension error: “Unchecked runtime.lastError while running browserAction.setIcon: No tab with id”

我只是一个虾纸丫 提交于 2019-11-29 05:31:17
I'm coding my Google Chrome Extension where I set the app's icon from the background script as such: try { objIcon = { "19": "images/icon19.png", "38": "images/icon38.png" }; chrome.browserAction.setIcon({ path: objIcon, tabId: nTabID }); } catch(e) { } Note that I wrapped the call in try/catch block. Still, sometimes I'm getting the following message in the console log: Unchecked runtime.lastError while running browserAction.setIcon: No tab with id: 11618. It's hard to debug this error because it seems to come up only when I close or reload the Chrome tab, it doesn't have a line number or any

Helgrind (Valgrind) and OpenMP (C): avoiding false positives?

﹥>﹥吖頭↗ 提交于 2019-11-29 02:49:00
The documentation for the Valgrind thread error detection tool Helgrind, found here warns that, if you use GCC to compile your OpenMP code, GCC's OpenMP runtime library ( libgomp.so ) will cause a chaos of false positive reports of data races, because of its use of atomic machine instructions and Linux futex system calls instead of POSIX pthreads primitives. It tells you that you can solve this problem, however, by recompiling GCC with the --disable-linux-futex configuration option. So I tried this. I compiled and installed to a local directory ( ~/GCC_Valgrind/gcc_install ) a new GCC version

Is it safe if more git commands are run on the same repo in parallel?

醉酒当歌 提交于 2019-11-29 02:02:28
问题 I am interested if it is safe to run things like git push and git commit in parallel (for example in cron jobs, jenkins jobs etc.). Is there some locking mechanism built-in in git so these operations are serialized or this can corrupt the repository? 回答1: Yes. Git works by writing references in a manner that allows for this. If you are doing a commit at the same time as a push, push will only go from the references down to the objects they contain. If the commit finishes and updates the

Handling race condition in model.save()

馋奶兔 提交于 2019-11-28 23:21:09
How should one handle a possible race condition in a model's save() method? For example, the following example implements a model with an ordered list of related items. When creating a new Item the current list size is used as its position. From what I can tell, this can go wrong if multiple Items are created concurrently. class OrderedList(models.Model): # .... @property def item_count(self): return self.item_set.count() class Item(models.Model): # ... name = models.CharField(max_length=100) parent = models.ForeignKey(OrderedList) position = models.IntegerField() class Meta: unique_together =

Atomic operations in Django?

折月煮酒 提交于 2019-11-28 17:04:19
I'm trying to implement (what I think is) a pretty simple data model for a counter: class VisitorDayTypeCounter(models.Model): visitType = models.CharField(max_length=60) visitDate = models.DateField('Visit Date') counter = models.IntegerField() When someone comes through, it will look for a row that matches the visitType and visitDate; if this row doesn't exist, it will be created with counter=0. Then we increment the counter and save. My concern is that this process is totally a race. Two requests could simultaneously check to see if the entity is there, and both of them could create it.

How do I obtain, and synchronize, a complete list of all X11 windows?

对着背影说爱祢 提交于 2019-11-28 16:55:06
I want to monitor all the open windows under X11. Currently, I'm doing this as follows: Initially walking the whole tree by recursively calling XQueryTree from the root window Listening for substructure changes on the whole desktop: XSelectInput( display, root_window, SubstructureNotifyMask | PropertyChangeMask ) Handling all MapNotify, UnmapNotify and DestroyNotify events, updating my own list of windows in the process I'm mainly worried about point 1. During the recursion, XQueryTree will be called multiple times. Is there any way to ensure that the tree does not change in the meantime? In

Private constructor to avoid race condition

寵の児 提交于 2019-11-28 15:39:17
I am reading the book Java Concurrency in Practice session 4.3.5 @ThreadSafe public class SafePoint{ @GuardedBy("this") private int x,y; private SafePoint (int [] a) { this (a[0], a[1]); } public SafePoint(SafePoint p) { this (p.get()); } public SafePoint(int x, int y){ this.x = x; this.y = y; } public synchronized int[] get(){ return new int[] {x,y}; } public synchronized void set(int x, int y){ this.x = x; this.y = y; } } I am not clear where It says The private constructor exists to avoid the race condition that would occur if the copy constructor were implemented as this (p.x, p.y); this