locking

What is equivalent of the C# lock statement in PHP?

穿精又带淫゛_ 提交于 2019-12-07 14:50:14
问题 For concurrency and ensuring the integrity of the data, how would you obtain a mutual-exclusion lock for a given object? Would you need to use locking within the database, or a file, or does PHP support something like this? 回答1: PHP doesn't support multithreading so there's no locking mechanism for objects. If you want to lock a file you could use flock for that. There's no need to lock database as database engines usually can handle multiple connections. 回答2: Bare in mind PHP is not

JPA Pessimistic Lock Not Working

≯℡__Kan透↙ 提交于 2019-12-07 13:35:47
问题 I'm using Spring Boot, JPA, Oracle 12C and a Typed Query below to select 'NEW' items to process. Once I've selected a 'NEW' item, I update its status so it's no longer eligible for selection but I'm seeing a concurrency issue with the same items getting picked up. I read here that i needed to set a 'LockModeType.PESSIMISTIC_WRITE' on the query to prevent other Threads from selecting the same row but it doesn't appear to be working. Have I missed something below or do i need another

ASP.NET lock thread method

家住魔仙堡 提交于 2019-12-07 13:15:45
问题 I'm developing an ASP.NET forms webapplication using C#. I have a method which creates a new Order for a customer. It looks similar to this; private string CreateOrder(string userName) { // Fetch current order Order order = FetchOrder(userName); if (order.OrderId == 0) { // Has no order yet, create a new one order.OrderNumber = Utility.GenerateOrderNumber(); order.Save(); } return order; } The problem here is, it is possible that 1 customer in two requests (threads) could cause this method to

How does this recursive synchronized call not deadlock?

主宰稳场 提交于 2019-12-07 13:13:59
问题 I have a set of methods that all synchronize to the class object (can't use self, because multiple instances of this object could be used in multiple threads). Some of those methods call other methods in the class that also synchronize on the class object. Somehow this works and does not cause the deadlock I would expect it to. I would assume that testA would be blocked from running because testB already has a lock on the class object, but this apparently isn't the case. Is it something

Java EE concurrency & locking

こ雲淡風輕ζ 提交于 2019-12-07 11:05:19
问题 I have a MDB (Message driven bean) that receives messages with String which represent a word. Also I have a table in the database. The MDB should store in the table, the words and the number of times each word was received (counter). The problem is that to get better performance the MDB started in many instances and when the same new word is received by different instances they both create the same row with count of 1. To solve this I should make the word field unique and then the second

Metro App FileIO.WriteTextAsync Multiple Threads

扶醉桌前 提交于 2019-12-07 07:59:04
问题 I have a method which is called frequently from multiple threads. It involves writing to disk using await FileIO.WriteTextAsync . This works fine when it is called from a single thread, but once I start doing this in multiple threads, I get this error: The process cannot access the file because it is being used by another process. I know what the error means, but I'm not sure how to work around it. Normally, I would create a lock(object) statement, to ensure that the file is being accessed by

How Erlang processes access mailbox concurrently

*爱你&永不变心* 提交于 2019-12-07 07:32:49
问题 There are lots of info regarding how to use erlang mailbox, but seldom to find a paper or document describe how erlang actual access mailbox concurrently internally within the VM. To my understanding, Erlang VM must have to do locking or CAS action to secure message integrity. Is there any sophisticate way of method behind erlang's curtain 回答1: By mailbox I'm assuming you mean the process mailbox, the one messages are inserted into. Fun question! There's some conversation here about the

Is there any idiomatic explicit use of mutex::lock() or unlock()?

自作多情 提交于 2019-12-07 07:28:54
问题 The recommended way to use a mutex for locking a critical region of code is via RAII, i.e. mutex_type mutex; { // start of critical region std::lock_guard<mutex_type> lock(mutex); // first statement in critical region // ... do critical stuff, may throw an exception } // end of critical region so that when an exception is thrown within the critical region, the mutex will still be unlocked (by the destructor of std::lock_guard ). However, this way the members mutex::lock() and mutex::unlock()

C# file is being used by another process

不想你离开。 提交于 2019-12-07 07:28:52
问题 I am not sure how can I solve my problem. From time to time I get the error: "The process cannot access the file 'xxxx' because it is being used by another proces". Here is my method where the error happens: private static void write_history(int index, int time_in_sec, int[] sent_resources) { string filepath = "Config\\xxx.txt"; int writing_index = 0; if (File.Exists(filepath)) { System.Threading.Thread.Sleep(5000); StreamReader reader = new StreamReader(new FileStream(filepath, FileMode.Open

MySQL locking in Duplicate Key Error

元气小坏坏 提交于 2019-12-07 06:27:08
问题 From the docs: If a duplicate-key error occurs, a shared lock on the duplicate index record is set. This use of a shared lock can result in deadlock should there be multiple sessions trying to insert the same row if another session already has an exclusive lock. This can occur if another session deletes the row. Going with the example in the docs, Suppose that an InnoDB table t1 has the following structure: CREATE TABLE t1 (i INT, PRIMARY KEY (i)) ENGINE = InnoDB; Now suppose that three