locking

C# concurrency, locking and dictionary objects

亡梦爱人 提交于 2019-12-08 12:38:47
问题 I have a bunch of DB entities that are loaded into DB objects. The same DB entity may be loaded into more than DB object. Periodically a DB entity will require special processing. This processing must be performed by one thread at a time. Locking is in order here. EDIT: Important note: the process calls a slow web service. This is what I'm trying to prevent concurrency. I don't see how this can be done safely w/o locks. So I create an “padlock” object that will be referenced by the DB objects

Optimistic “locking” with Django transactions

断了今生、忘了曾经 提交于 2019-12-08 11:55:58
问题 I have a function fn() that needs to atomically do some database work that relies on some set of data not changing during its execution (true most of the time). What is the correct way to implement this in Django? Basically I'd like to do something like this: def ensure_fn_runs_successfully(): # While commit unsuccessful, keep trying while not fn(): pass @transaction.atomic def fn(): data = read_data_that_must_not_change() ... do some operations with the data and perform database operations .

Database row lock during multiple transactions

僤鯓⒐⒋嵵緔 提交于 2019-12-08 11:25:54
问题 Hi and Happy New Year :) I'm using Postgresql and I need a way to enable a worker process to lock a specific row, while that process operates on that row. It is essentially a table of actions which should be executed once and only once. Each process should grab a different row to operate on. During this 'operation' the worker process will calculate some value and insert into the database in a transaction multiple times (it will alter between calculating and inserting into the database). I don

Do we need an mfence in the unlock() function of Peterson's lock on x86?

微笑、不失礼 提交于 2019-12-08 10:50:39
问题 Peterson's lock code taken from (german) wikipedia: # define FALSE 0 # define TRUE 1 # define N 2 int turn; int interested[N]; void enter_region(int process) { int other; other = 1 - process; interested[process] = TRUE; turn = other; while (interested[other] == TRUE && turn == other) ; } void leave_region(int process) { interested[process] = FALSE; } Can somebody think of an example where a bug is happening without an mfence in the leave_region function? N.B.: I know for sure that a mfence is

SSHClient jsch bufferedinputstream LOCK

旧街凉风 提交于 2019-12-08 09:10:03
问题 When executing command via SShClient based on jsch session get lock: Exec thread devapp090@1046" prio=5 tid=0x14 nid=NA runnable java.lang.Thread.State: RUNNABLE at java.io.FileInputStream.readBytes(FileInputStream.java:-1) at java.io.FileInputStream.read(FileInputStream.java:220) at java.io.BufferedInputStream.read1(BufferedInputStream.java:256) at java.io.BufferedInputStream.read(BufferedInputStream.java:317) - locked <0x420> (a java.io.BufferedInputStream) at com.jcraft.jsch.ChannelSession

PostgreSQL locking mode

寵の児 提交于 2019-12-08 07:23:01
问题 From this doc http://www.postgresql.org/docs/current/static/explicit-locking.html I knew PostgreSQL provides various lock modes to control concurrent access to data in tables. My problem is I have many sessions will accessing my DB , but I'm confuse should I made 1 big table with 40 column or many tables with fewer column (one to one relationship). Because when I select the data I will select all of it ---> it takes more time when I select from many tables using INNER JOIN, but it takes less

For api < 16: How to detect if PIN/password/pattern is required to unlock phone?

旧街凉风 提交于 2019-12-08 07:12:36
问题 I already know these two cases: 1) for devices using api >= 16, one could just use the method isDeviceSecure() from KeyguardManager and that would return true if any locking mechanism is used on the device (pattern, passcode, password, etc.) 2) for devices using api <= 15, one could do something like if (Settings.Secure.getInt(getContentResolver(), Settings.Secure.LOCK_PATTERN_ENABLED) == 0) , but that would only check for screen locking pattern (not passcode, password, etc.) So my question

Multithreading and Locking (Thread-Safe operations)

做~自己de王妃 提交于 2019-12-08 06:24:17
问题 So I have a class with a few methods which all use locking in order to prevent weird things happening when someone uses an instance of my class with multiple threads accessing it: public class SomeRandomClass { private object locker = new object(); public void MethodA() { lock (locker) { // Does something MethodB(); } } public void MethodB() { lock (locker) { // Does something else } } } As we can see, MethodB() is automatically accessed by MethodA() , but that won't work since MethodA() has

How To Lock Java Process To Memory? (MLock)

﹥>﹥吖頭↗ 提交于 2019-12-08 06:22:21
问题 I found this stack overflow question from 2010: Lock or Pin java process into memory Basically it says the way to lock a java process to memory is by using JNI. The example it points to is a broken link. Now that it's 2013 my question is.. Is there a better way? And is there an example somewhere of someone using mlock in Java? I'm extremely inexperienced with JNI and with C code in general, but quite familiar with Java (although I've NEVER used JNI). Thanks 回答1: I'm wondering if there's a

Linux File Locking in Java

放肆的年华 提交于 2019-12-08 05:40:17
问题 I know we can lock a file in linux using flock(). However, NFS drive might not support file lock. I am thinking to implement some custom file lock logic in my java code, to support file lock on any drive. Can anyone suggest a good practice? Thanks, 回答1: File locking must be done by the operating system kernel / file system drivers, unless you're thinking of a narrower scope like just locking between the threads of a single process. There's no way all the other processes on the system will