locking

How I make result of SQL querys with LIMIT different in each query?

橙三吉。 提交于 2019-12-13 05:41:32
问题 I have the following SQL: SELECT id, url FROM link WHERE visited = false ORDER BY id LIMIT 500; --*500 is only a example I'm making a webcrawler and there is a table with links. This SQL returns the links to visit, but dont all them, only the quantitiy defined in the limit clause. I will use threads and if the first execute this query, it will obtains the first 500 links, if the second thread execute the same query, it will obtains the next 500 links. In other words, first thead obtains links

how to implement locking within function in multiple threads f#

天大地大妈咪最大 提交于 2019-12-13 05:04:55
问题 I created a mutable list called tickets that contains type Ticket. I also have a bookSeat function that imitates booking a seat.Since F# list type is immutable, my bookSeat function always returns a new, modified, copy of tickets list. open System open System.Threading type Ticket = {seat:int; customer:string} let mutable tickets = [for n in 1..10 -> {Ticket.seat = n; Ticket.customer = ""}] let bookSeat _ = Console.WriteLine("Enter seat number: ") let seatNo = int(Console.ReadLine()) Console

How to know the lock status for a row, without updating the record

旧街凉风 提交于 2019-12-13 04:36:33
问题 I am using the readcommited isolation level to update a row in one transaction. From other transaction, How should I find there is a lock placed on the same row without trying to update the row. Any idea? 回答1: The only way to check for a lock is by obtaining the lock your self. This is not specific to databases, is a general issue with concurrency. Any form of API that 'checks' if a lock is held or not is fundamentally broken because by definition any action performed based on the result of

.NET app locks file

倾然丶 夕夏残阳落幕 提交于 2019-12-13 03:45:07
问题 Okay I;m really new to VB.NET and desktop application development. Simplified this is what is happening in my application: Dim Files() As New List(Of IO.FileInfo) Files.Add( (New IO.FileInfo("C:\img1.jpg")) ) Files.Add( (New IO.FileInfo("C:\img2.jpg")) ) 'Picture is a Windows.Forms.PictureBox in my WinForm ' Picture.Image = New System.Drawing.Bitmap(Files(0).FullName) Picture.image = Nothing CurrentFile = Files(0) 'Show next pic (img2)' Files.RemoveAt(0) Picture.Image = New System.Drawing

InnoDB locking for INSERT/UPDATE concurrent transactions

三世轮回 提交于 2019-12-13 03:05:32
问题 I'm looking to ensure isolation when multiple transactions may execute a database insert or update, where the old value is required for the process. Here is a MVP in python-like pseudo code, the default isolation level is assumed: sql('BEGIN') rows = sql('SELECT `value` FROM table WHERE `id`=<id> FOR UPDATE') if rows: old_value, = rows[0] process(old_value, new_value) sql('UPDATE table SET `value`=<new_value> WHERE `id`=<id>') else: sql('INSERT INTO table (`id`, `value`) VALUES (<id>, <new

Multiple python threads writing to different records in same list simultaneously - is this ok?

China☆狼群 提交于 2019-12-13 03:02:05
问题 I am trying to fix a bug where multiple threads are writing to a list in memory. Right now I have a thread lock and am occasionally running into problems that are related to the work being done in the threads. I was hoping to simply make an hash of lists, one for each thread, and remove the thread lock. It seems like each thread could write to its own record without worrying about the others, but perhaps the fact that they are all using the same owning hash would itself be a problem. Does

Using SQL dB column as a lock for concurrent operations in Entity Framework

跟風遠走 提交于 2019-12-13 02:57:44
问题 We have a long running user operation that is handled by a pool of worker processes. Data input and output is from Azure SQL. The master Azure SQL table structure columns are approximated to [UserId, col1, col2, ... , col N, beingProcessed, lastTimeProcessed ] beingProcessed is boolean and lastTimeProcessed is DateTime. The logic in every worker role is as shown below and with multiple workers processing (each with their own Entity Framework layer), in essence beingProcessed is being used a

JPA LockModeType.PESSIMISTIC_WRITE doesn't work as expected. App without keys, reads snapshot of database at locking

心已入冬 提交于 2019-12-13 02:40:03
问题 I have two apps running identical code, querying the same Oracle database with the help of hibernate. There is a table that keeps emails to be sent. Both apps run a scheduler that query a column on this table for "QUEUED" string (which marks emails to be sent), create and send emails and at the end, update, "QUEUED" to "SENT" so these emails won't be sent again. In theory, I want one app to read some rows, lock them from reading and writing, update them and unlocking for the other app to use.

What effect does the monitor object have in synchronized block?

邮差的信 提交于 2019-12-12 20:52:35
问题 After hours of reading i am still struggling to understand what the monitor object exactly does. A demo to show what i mean: public class Demo { public static Bathroom bathroom = new Bathroom(); public static Kitchen kitchen = new Kitchen(); public static void main(String[] args) { (new Thread(new Roommate("bob"))).start(); (new Thread(new Roommate("john"))).start(); (new Thread(new Mom())).start(); } } class Bathroom { public void use(String who) { synchronized (Demo.kitchen) { System.out

lock vs Interlocked.Exchange

邮差的信 提交于 2019-12-12 18:36:04
问题 I have an application which constantly (+-100ms) reads orders from a PLC and then puts them in a model which then gets read by multiple clients. For this im using the lock statement. Order Reading thread : lock (model) { //update object } Clients Reading : lock (model) { //serialize object to json string } send over tcp stream to client. But i could also use for the update : Interlocked.ExChange(oldObj, newObj) I don't want my clients to have to wait for a lock that is happening in the Order