locking

How to use Multithreading, locks, Socket Programming

独自空忆成欢 提交于 2019-12-22 00:14:41
问题 For last 48 hours, I have been trying to understand Multithreading and Socket Programming . I tried to implement socket programming and had success when not using multithreading. I am new to both of the topics and have raised 2-3 question on stack itself needing help on the same. After googling a lot I found an article that explains Socket Programming and Multithreading , but I still have a lot of doubts in this article and got stuck at Figure 5 in the article. private void AcceptConnections(

Is there any way to determine the number of threads waiting to lock in C#?

妖精的绣舞 提交于 2019-12-21 22:40:07
问题 I'm using simple locking in C# using the lock statement. Is there any way to determine how many other threads are waiting to get a lock on the object? I basically want to limit the number of threads that are waiting for a lock to 5. My code would throw an exception if a sixth thread needs to get a lock. 回答1: This can be easily accomplished via the Semaphore class. It will do the counting for you. Notice in the code below that I use a semaphore to do a non-blocking check of the number of

How to implement locking in a multi process system?

可紊 提交于 2019-12-21 22:12:57
问题 We are running lots of jenkins projects in parallel. We are using python, and we have chosen to manage the virtual environments with pyenv. Unfortunately, pyenv has a well-known race condition. To work around the problem, I would like to implement locking at the process level. What I want to do is: lock some resource (a file?) do my pyenv stuff unlock the resource My scripts are written in bash. How can I implement resource locking / unlocking in bash? 回答1: So your friend in the unix world

How to prevent overwriting an object someone else has modified

孤街醉人 提交于 2019-12-21 21:37:50
问题 I would like to find a generic way of preventing to save an object if it is saved after I checked it out. We can assume the object has a timestamp field that contains last modification time. If I had checked out (visited a view using a ModelForm for instance) at t1 and the object is saved again at t2 , given t2 > t1 I shouldn't be able to save it. 回答1: Overwrite the save method that would first check the last timestamp: def save(self): if(self.id): foo = Foo.objects.get(pk=self.id) if(foo

Futex based locking mechanism

落爺英雄遲暮 提交于 2019-12-21 21:14:12
问题 Somebody can tell me an example of using locking mechanism based on futex? (for muticore x86 CPU, CentOS) 回答1: Pthreads' mutexes are implemented using futexes on recent versions of Linux. Pthreads is the standard C threading API on Linux, and is part of the Posix standard, so you can easily port your program to other Unix-like systems. You should avoid using futexes directly unless you have very unusual needs, because they're very hard to use correctly - use pthreads, or a higher-level,

Data mismatch when querying with different indexes

血红的双手。 提交于 2019-12-21 18:35:27
问题 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]

Data mismatch when querying with different indexes

时间秒杀一切 提交于 2019-12-21 18:35:27
问题 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]

Is there a .Net StyleCop rule which warns about lock(this), lock(typeof, lock(<string obj>, etc.?

删除回忆录丶 提交于 2019-12-21 17:23:37
问题 These 3 types of lock are apparently bad. What other type of locking is bad? Are there Stylecop / FxCop rules that would catch this? If not, then would you please help me with a custom rule implementation? They code for all of them must be similar, right? Thank you. 回答1: The samples (you may need to allow popups in your browser) of John Robbins' Debugging Microsoft .NET Applications book contain sources for such FxCop rules (DoNotLockOnPublicFields, DoNotLockOnThisOrMe, DoNotLockOnTypes, etc.

Object is currently in use elsewhere

╄→гoц情女王★ 提交于 2019-12-21 17:05:15
问题 I'm getting this error, and it looks like it's because the same Bitmap object is being accessed by different threads. However I am using locks everywhere with it. public class MySingleInstanceClass { private Object locker = new Object(); private Bitmap myImage = new Bitmap(100, 100); public Bitmap MyImage { get { lock (locker) return myImage; } private set { lock (locker) myImage = value; } } private void Refresh() { lock (locker) { var g = Graphics.FromImage(myImage); // do more processing }

How to lock a whole table in symfony2 with doctrine2?

有些话、适合烂在心里 提交于 2019-12-21 16:51:16
问题 I need to lock a whole table (not a single row) with doctrine, I would like to do this without native queries if possible. The documentation for pessimistic locking only describes how to lock specific entities through these methods: EntityManager#find EntityManager#lock Query#setLockMode I have a transaction that needs to insert a row whose values depend on the values of the rest of the rows in the table, so I need to prevent two transactions performing at the same time on that table. I'm