locking

Again double-checked locking and C#

为君一笑 提交于 2019-12-10 14:29:16
问题 Recently I have been refactoring some of my C# code and I found a few double-checked locking practices taking place. I didn't know it was a bad practice back then and I really want to get rid of it. The problem is that I have a class that should be lazily initialized and frequently accessed by lots of threads. I also do not want to move the initialization to a static initializer, because I am planning to use a weak reference to keep the initialized object from staying too long in the memory.

PHP PDO MySQL and how does it really deal with MySQL transactions?

折月煮酒 提交于 2019-12-10 14:24:51
问题 I am trying to get over it, but I just can't understand the logic behind the process of transactions in PHP using PDO and MySQL. I know this question is going to be long, but I think it's worth it. Given that I read a lot about MySQL transactions, how they are handled by the server, how they relate to locks and other implicit commit statements, etc., not only here on SO, but also on the MySQL and PHP manuals: Mysql transactions within transactions Difference between SET autocommit=1 and START

INNER JOIN and locks

主宰稳场 提交于 2019-12-10 14:07:27
问题 I have two tables TableA and TableB which have information I want to retrieve and update concurrently. When I use SELECT TOP 2 SomeFieldA FROM TableA WITH (ROWLOCK , UPDLOCK , READPAST) everything works fine and Process 1 sees, say, rows 1 and 2, while Process 2 sees, say, rows 3 and 4. This is the expected behaviour. Also, when I execute EXEC sp_lock I see only two KEY entries. However, when I change the statement to SELECT TOP 2 SomeFieldA FROM TableA WITH (ROWLOCK , UPDLOCK , READPAST)

What is the name of this locking technique?

旧时模样 提交于 2019-12-10 14:03:11
问题 I've got a gigantic Trove map and a method that I need to call very often from multiple threads. Most of the time this method shall return true . The threads are doing heavy number crunching and I noticed that there was some contention due to the following method (it's just an example, my actual code is bit different): synchronized boolean containsSpecial() { return troveMap.contains(key); } Note that it's an "append only" map: once a key is added, is stays in there forever (which is

Locking on an object

三世轮回 提交于 2019-12-10 13:51:49
问题 I often see code like that which is shown here, ie where an object is allocated and then used as a "lock object". It seems to me that you could use any object for this, including the event itself as the lock object. Why allocate a new object that does nothing? My understanding is that calling lock() on an object doesn't actually alter the object itself, nor does it actually lock it from being used, it's simply used as a placeholder for multiple lock statements to anchor on. public class Shape

Can a read instruction after an unrelated lock statement be moved before the lock?

放肆的年华 提交于 2019-12-10 13:43:38
问题 This question is a follow-up to comments in this thread. Let's assume we have the following code: // (1) lock (padlock) { // (2) } var value = nonVolatileField; // (3) Furthermore, let's assume that no instruction in (2) has any effect on the nonVolatileField and vice versa. Can the reading instruction (3) be reordered in such a way that in ends up before the lock statement (1) or inside it (2) ? As far as I can tell, nothing in the C# Specification (§3.10) and the CLI Specification (§I.12.6

mysql lock error or bug?

眉间皱痕 提交于 2019-12-10 13:28:55
问题 here we go: mysql> LOCK TABLES radcheck WRITE; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM radcheck WHERE id NOT IN ( -> SELECT id FROM ( -> SELECT id FROM radcheck WHERE attribute = 'Password' GROUP BY UserName HAVING COUNT(*) > 1 -> ) AS c -> ); ERROR 1100 (HY000): Table 'radcheck' was not locked with LOCK TABLES WTF? EDIT SET AUTOCOMMIT = 0 -> ; Query OK, 0 rows affected (0.00 sec) mysql> LOCK TABLES radcheck WRITE; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM

How to check if a file is locked or not?

拟墨画扇 提交于 2019-12-10 13:25:37
问题 I have the following code where I want to check if the file is locked or not. If not then I want to write to it. I am running this code by running them simultaneously on two terminals but I always get "locked" status every time in both tabs even though I haven't locked it. The code is below: #include <fcntl.h> #include <stdio.h> #include <unistd.h> int main() { struct flock fl,fl2; int fd; fl.l_type = F_WRLCK; /* read/write lock */ fl.l_whence = SEEK_SET; /* beginning of file */ fl.l_start =

When should I use Scope Locking (Application, Server, etc…) vs named locking in ColdFusion?

主宰稳场 提交于 2019-12-10 12:37:22
问题 When is it appropriate to use <cflock scope="application"> or it's ilk as opposed to <cflock name="foo">? Specifically, I'm interested in using CFLock to protect shared objects in the application, session, or server scopes, but I'm also interested in finding out about different uses of locking in ColdFusion. 回答1: You should use when reading and writing from things that can change in the application scope. For example: <cfquery name="application.myData"> select * from myTable </cfquery> You

What precisely does a “lock” lock?

余生长醉 提交于 2019-12-10 12:27:35
问题 I'm working on a class that creates and manages multiple socket connections and which will be forwarding information received from the sockets to the main thread and vice-versa. Multi-threading where I'm passing so much information in and out is new to me (as is most things in C#), so I need a clarification on what exactly locks do. When I lock a section of a method does it only ensure that no other thread can enter that section of code or does it actually prevent all the variables in that