locking

C# Lock WinForm Controls

余生颓废 提交于 2019-12-04 12:38:55
In a program I have written users can add controls to the form and move them around and set some properties in a pseudo design mode. I want to be able to lock all these controls into one location when they press a button to switch to "data mode". How can I do this? I wanted to do be able to loop through all the controls and use the Lock Property but I noticed it didn't show up in intellisense. Thanks! I am assuming by "pseudo-design mode" you do mean that your application is in a run-time state, and the end-user is experiencing a "virtual design mode" : please correct me if I am wrong. But, I

C# - Locking a resource when obtained from dictionary

戏子无情 提交于 2019-12-04 11:50:44
I have a Dictionary that tracks objects (ClientObject). Both the dictionary and ClientObject's are accessed by multiple threads. When I modify or read any object in this dictionary, I obtain a read or write lock on the dictionary using ReaderWriterLockSlim (rwl_clients) then obtain an exclusive lock on the actual object. I just wanted to know if I am using these .net threading facilities correctly Example: rwl_clients.EnterReadLock(); ClientObject clobj; if(!m_clients.TryGetValue(key, out clobj)) return; rwl_clients.ExitReadLock(); SomeMethod(clobj); SomeMethod(ClientObject clobj) would do

Does the CLR perform “lock elision” optimization? If not why not?

倾然丶 夕夏残阳落幕 提交于 2019-12-04 11:37:54
问题 The JVM performs a neat trick called lock elision to avoid the cost of locking on objects that are only visible to one thread. There's a good description of the trick here: http://www.ibm.com/developerworks/java/library/j-jtp10185/ Does the .Net CLR do something similar? If not then why not? 回答1: It's neat, but is it useful? I have a hard time coming up with an example where the compiler can prove that a lock is thread local. Almost all classes don't use locking by default, and when you

Data base pessimistic locks with Spring data JPA (Hibernate under the hood)

ⅰ亾dé卋堺 提交于 2019-12-04 11:36:14
I need some help with pessimistic entity locking. I'm using PostgreSQL and Spring data JPA (hibernate 5 under the hood) in my application. So, I want to show a task I've faced with. I have some user accounts with money: @lombok.Data //Used to generate getters and setters @Entity class AccountEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private Long balance; } And payments, that allows to transfer money from one account to another @lombok.Data @Entity class PaymentEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private

ReaderWriterLock for array

↘锁芯ラ 提交于 2019-12-04 11:32:35
I have an array, that represents an inventory, with nearly 50 elements (items: some costum objects) and I need a readerwritelock for it (okay, i think a simple lock would be enough too). It should support both reference changing and value changing. As reading and writing to different position of the array is threadsafe ( Proof ) I want to ensure that multiple read/write operations on the same array position is also threadsafe. I surely could create 50 readerwriterlocks, but I don't want that ;) Is there a way to archive this? (I know ConcurrentList/Dictionary/etc. but I want an array...)

Data mismatch when querying with different indexes

吃可爱长大的小学妹 提交于 2019-12-04 11:26:37
I stumbled upon with a very curious case. We have a SQL Server 2012 database and such a table CREATE TABLE [dbo].[ActiveTransactions] ( [Id] [BIGINT] IDENTITY(1,1) NOT NULL, [Amount] [DECIMAL](12, 4) NOT NULL, [TypeId] [SMALLINT] NOT NULL, [GameProviderId] [SMALLINT] NULL, [UserId] [INT] NOT NULL, [Checksum] [NVARCHAR](150) NOT NULL, [Date] [DATETIME2](7) NOT NULL, [ExternalKey] [VARCHAR](60) NULL, [ExternalDescription] [NVARCHAR](1000) NULL, [OperatorId] [SMALLINT] NULL, [GameId] [NVARCHAR](50) NULL ) This table has multiple indexes but the two which I want to talk about here are PK

Is Map of Locks a safe approach for concurrent operations

坚强是说给别人听的谎言 提交于 2019-12-04 11:04:40
The requirement is only single thread must be allowed to perform user management (create/update/import) operations but multiple threads are not allowed to perform user operations simultaneously for the same user. For example, When Thread A is creating User A then concurrently Thread B must not be allowed to import User A Or Creating User A but Thread B is allowed to import User B. Is the below code thread safe for these requirements? public class UserManagement { ConcurrentHashMap<Integer, Lock> userLock = new ConcurrentHashMap<>(); public void createUser(User user, Integer userId) { Lock lock

Acquiring multiple locks atomically in java

﹥>﹥吖頭↗ 提交于 2019-12-04 10:57:11
I have the following code: Note: I simplified the code as much as possible for readability. If I forgot any critical pieces let me know. public class User(){ private Relations relations; public User(){ relations = new Relations(this); } public getRelations(){ return relations; } } public class Relations(){ private User user; public Relations(User user){ this.user = user; } public synchronized void setRelation(User user2){ Relations relations2 = user2.getRelations(); synchronized(relations2){ storeRelation(user2); if(!relations2.hasRelation(user)) relations2.setRelation(user); } } public

DataReader Behaviour With SQL Server Locking

纵饮孤独 提交于 2019-12-04 10:34:01
We are having some issues with our data layer when large datasets are returned from a SQL server query via a DataReader . As we use the DataReader to populate business objects and serialize them back to the client, the fetch can take several minutes (we are showing progress to the user :-)), but we've found that there's some pretty hard-core locking going on on the affected tables which is causing other updates to be blocked. So I guess my slightly naive question is, at what point are the locks which are taken out as a result of executing the query actually relinquished? We seem to be finding

MongoDB Read/Write Locks

北城余情 提交于 2019-12-04 09:46:08
I'm planning to create an application using nodejs that users can rate the products. From what I heard locks are different in mongodb than mySql. I'm worried that if let's say 10 users vote on a product at a same time, Mongodb can't handle it and the result other users see is not correct. I looked at similar questions but I'm still confused! Is mongodb a good choice or should I just use Mysql? I'd appreciate your help Locking is described in this Concurrency FAQ in the MongoDB documentation. In particular: MongoDB uses a readers-writer lock that allows concurrent reads access to a database but