locking

How to delete many rows from frequently accessed table

喜欢而已 提交于 2019-12-01 17:56:46
I need to delete the majority (say, 90%) of a very large table (say, 5m rows). The other 10% of this table is frequently read, but not written to. From " Best way to delete millions of rows by ID ", I gather that I should remove any index on the 90% I'm deleting, to speed up the process (except an index I'm using to select the rows for deletion). From " PostgreSQL locking mode ", I see that this operation will acquire a ROW EXCLUSIVE lock on the entire table. But since I'm only reading the other 10%, this ought not matter. So, is it safe to delete everything in one command (i.e. DELETE FROM

Is there any reason to lock on something other than new object()?

自闭症网瘾萝莉.ら 提交于 2019-12-01 17:46:52
object theLock = new object(); ... lock (theLock) { ... } I always use a new object() for this, but I'm wondering: are there any circumstances in which you would lock on a more specific type? In case of a new , the Type doesn't matter, the instance do. In this case you're talking about a synclock object : an object which is used to lock code(s) section(s) to prevent concurrent access. Using another Type than object for a synclock is a waste of memory because you don't use this instance for anything else. There're circumstances in which you can lock another type : when you need to lock a

Thread synchronization. Why exactly this lock isn't enough to synchronize threads [duplicate]

こ雲淡風輕ζ 提交于 2019-12-01 17:37:36
Possible Duplicate: Threads synchronization. How exactly lock makes access to memory 'correct'? This question is inspired by this one. We got a following test class class Test { private static object ms_Lock=new object(); private static int ms_Sum = 0; public static void Main () { Parallel.Invoke(HalfJob, HalfJob); Console.WriteLine(ms_Sum); Console.ReadLine(); } private static void HalfJob() { for (int i = 0; i < 50000000; i++) { lock(ms_Lock) { }// empty lock ms_Sum += 1; } } } Actual result is very close to expected value 100 000 000 (50 000 000 x 2, since 2 loops are running at the same

What type of locking mechanism does lock statement use

送分小仙女□ 提交于 2019-12-01 17:12:13
Does the c# lock keyword use a 'yielding', 'spin-locking' or hybrid approach to handle contention? So far my searches on the .net lock statement hasn't turned up an answer. I will post if I do find any more. So far all I could find is When should one use a spinlock ... with a nicely worded accepted answer by Mecki. But I am looking for some definitive answer or documentation regarding .net/c# if anyone has one. Following code: lock (_syncRoot) { // Do stuff } Is translated by the compiler to: Monitor.Enter(_syncRoot) try { // Do stuff } finally { Monitor.Exit(_syncRoot); } This is the naive

How to delete many rows from frequently accessed table

為{幸葍}努か 提交于 2019-12-01 17:11:19
问题 I need to delete the majority (say, 90%) of a very large table (say, 5m rows). The other 10% of this table is frequently read, but not written to. From "Best way to delete millions of rows by ID", I gather that I should remove any index on the 90% I'm deleting, to speed up the process (except an index I'm using to select the rows for deletion). From "PostgreSQL locking mode", I see that this operation will acquire a ROW EXCLUSIVE lock on the entire table. But since I'm only reading the other

On which systems/filesystems is os.open() atomic?

主宰稳场 提交于 2019-12-01 17:02:18
问题 This article states, that fd = os.open('foo.lock', os.O_CREAT|os.O_EXCL|os.O_RDWR) "is atomic on most filesystems". Is that true (on Unix and Windows)? On which filesystems? The docs state that mentioned flags are available on Unix and Windows, so it looks like a tempting, cross-platform method for file locking (the flags O_CREAT and O_EXCL ensure that the calling process creates the file). 回答1: For UN*X-compliant (certified POSIX / IEEE 1003.1 as per the OpenGroup) systems, the behaviour is

Does Apache read-lock files before serving them?

时间秒杀一切 提交于 2019-12-01 16:55:51
I have an mobile app that reads a JSON file that is stored on an Apache server. The contents of that JSON file are regenerated (using a PHP script) if something is changed via a GUI. I am worried that trying to overwrite the JSON file in the middle of it being served by Apache might cause problems. Does Apache obtain a read lock before serving files? If not, what will happen if I try to write it at the same time it is being served? No. On POSIX-compatible systems, all locks are advisory anyways, so even if apache would get a read lock, the other process could just write the file. You can

Thread synchronization. Why exactly this lock isn't enough to synchronize threads [duplicate]

梦想与她 提交于 2019-12-01 16:55:02
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Threads synchronization. How exactly lock makes access to memory 'correct'? This question is inspired by this one. We got a following test class class Test { private static object ms_Lock=new object(); private static int ms_Sum = 0; public static void Main () { Parallel.Invoke(HalfJob, HalfJob); Console.WriteLine(ms_Sum); Console.ReadLine(); } private static void HalfJob() { for (int i = 0; i < 50000000; i++) {

Locking on field or local variable?

我与影子孤独终老i 提交于 2019-12-01 16:52:21
After I read this question with an answer from Marc.... I sometimes see people locking on a local variable. Is this code broken? public void Do() { object o = new Object(); lock (o) { ... } } I believe object o = new Object(); should be outside the method as a Field . Since each thread is getting a new instance of o , there will be multiple locks. What am I missing here? Shouldn't it lock on fields in this specific case? I believe object o = new Object(); should be outside the method as a Field. Since each thread is getting a new instance of o , there will be multiple locks. Is there anything

On which systems/filesystems is os.open() atomic?

时光怂恿深爱的人放手 提交于 2019-12-01 16:47:21
This article states, that fd = os.open('foo.lock', os.O_CREAT|os.O_EXCL|os.O_RDWR) "is atomic on most filesystems". Is that true (on Unix and Windows)? On which filesystems? The docs state that mentioned flags are available on Unix and Windows, so it looks like a tempting, cross-platform method for file locking (the flags O_CREAT and O_EXCL ensure that the calling process creates the file). For UN*X-compliant (certified POSIX / IEEE 1003.1 as per the OpenGroup) systems, the behaviour is guaranteed as the OpenGroups specs for open(2) mandate this. Quote: O_EXCL If O_CREAT and O_EXCL are set,