race-condition

postgresql company id based sequence

允我心安 提交于 2019-11-28 12:39:28
I have a database with companies and their products, I want for each company to have a separate product id sequence. I know that postgresql can't do this, the only way is to have a separate sequence for each company but this is cumbersome. I thought about a solution to have a separate table to hold the sequences CREATE TABLE "sequence" ( "table" character varying(25), company_id integer DEFAULT 0, "value" integer ) "table" will be holt the table name for the sequence, such as products, categories etc. and value will hold the actual sequence data that will be used for product_id on inserts I

Ignoring locked row in a MySQL query

无人久伴 提交于 2019-11-28 10:20:37
I have one table that is read at the same time by different threads. Each thread must select 100 rows, execute some tasks on each row (unrelated to the database) then they must delete the selected row from the table. rows are selected using this query: SELECT id FROM table_name FOR UPDATE; My question is: How can I ignore (or skip) rows that were previously locked using a select statement in MySQL ? Kris Robison I typically create a process_id column that is default NULL and then have each thread use a unique identifier to do the following: UPDATE table_name SET process_id = #{process.id}

mysql insert race condition

China☆狼群 提交于 2019-11-28 07:41:30
How do you stop race conditions in MySQL? the problem at hand is caused by a simple algorithm: select a row from table if it doesn't exist, insert it and then either you get a duplicate row, or if you prevent it via unique/primary keys, an error. Now normally I'd think transactions help here, but because the row doesn't exist, the transaction don't actually help (or am I missing something?). LOCK TABLE sounds like an overkill, especially if the table is updated multiple times per second. The only other solution I can think of is GET_LOCK() for every different id, but isn't there a better way?

Race condition on x86

社会主义新天地 提交于 2019-11-28 07:23:43
Could someone explain this statement: shared variables x = 0, y = 0 Core 1 Core 2 x = 1; y = 1; r1 = y; r2 = x; How is it possible to have r1 == 0 and r2 == 0 on x86 processors? Source "The Language of Concurrency" by Bartosz Milewski . The problem can arise due to optimizations involving reordering of instructions . In other words, both processors can assign r1 and r2 before assigning variables x and y , if they find that this would yield better performance. This can be solved by adding a memory barrier , which would enforce the ordering constraint. To quote the slideshow you mentioned in

How to get last inserted row ID from WordPress database?

吃可爱长大的小学妹 提交于 2019-11-28 03:44:36
My WordPress plugin has a table with a AUTO_INCREMENT primary key field called ID. When a new row is inserted into the table, I'd like to get the ID value of the insertion. The feature is to using AJAX to post data to server to insert into DB. The new row ID is returned in the AJAX response to update client status. It is possible that multiple clients are posting data to server at the same time. So, I have to make sure that each AJAX request get the EXACT new row ID in response. In PHP, there is a method called mysql_insert_id for this feature.But, it is valid for race condition only if the

Difference between racearound condition and deadlock

僤鯓⒐⒋嵵緔 提交于 2019-11-28 03:15:33
What is the difference between a dead lock and a race around condition in programming terms? Think of a race condition using the traditional example. Say you and a friend have an ATM cards for the same bank account. Now suppose the account has $100 in it. Consider what happens when you attempt to withdraw $10 and your friend attempts to withdraw $50 at exactly the same time. Think about what has to happen. The ATM machine must take your input, read what is currently in your account, and then modify the amount. Note, that in programming terms, an assignment statement is a multi-step process. So

How can barriers be destroyable as soon as pthread_barrier_wait returns?

我与影子孤独终老i 提交于 2019-11-27 23:46:14
问题 This question is based on: When is it safe to destroy a pthread barrier? and the recent glibc bug report: http://sourceware.org/bugzilla/show_bug.cgi?id=12674 I'm not sure about the semaphores issue reported in glibc, but presumably it's supposed to be valid to destroy a barrier as soon as pthread_barrier_wait returns, as per the above linked question. (Normally, the thread that got PTHREAD_BARRIER_SERIAL_THREAD , or a "special" thread that already considered itself "responsible" for the

C++ memory model and race conditions on char arrays

依然范特西╮ 提交于 2019-11-27 23:15:54
Basically I have trouble understanding this: (from Bjarne FAQ) However, most modern processors cannot read or write a single character, it must read or write a whole word, so the assignment to c really is ``read the word containing c, replace the c part, and write the word back again.'' Since the assignment to b is similar, there are plenty of opportunities for the two threads to clobber each other even though the threads do not (according to their source text) share data! So how can char arrays exist without 3(7?) byte padding between elements? I think Bjarne is wrong about this, or at least,

Race condition and using Google Analytics Asynchronous (_gaq) synchronously

試著忘記壹切 提交于 2019-11-27 20:10:23
I have a website which is using Google Analytics newer asynchronous tracking method (_gaq). The problem I've run into is that I want to institute some specific link tracking and am worried that I will be creating a race condition. Basically, it's a news website so it has headlines which link to stories all over the place. A headline for a story might appear in 3 different places on a page, and appear on hundreds of other pages. Thus, in order to understand how our audience is interacting with the site we have to track how each specific headline block is used, and not just the destination.

KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?

我与影子孤独终老i 提交于 2019-11-27 18:47:35
问题 Note: I added kif to the title just for search indexing puposes, considering that most of the answer turned out to discuss it I'm looking for something like selenium for iOS, basically a test-automation/unit test framework that can run a certain UI scenario many many times until it crashes, which would help me narrow down the cause of a UI bug that happens very rarely and randomly. (and by the way, I've NSLogged every single line of code of datasource/table interaction and spent hours