race-condition

How to fix a race condition in node js + redis + mongodb web application

一曲冷凌霜 提交于 2019-12-02 11:03:36
I am building a web application that will process many transactions a second. I am using an Express Server with Node Js. On the database side, I am using Redis to store attributes of a user which will fluctuate continuously based on stock prices. I am using MongoDB to store semi-permanent attributes like Order configuration, User configuration, etc., I am hitting a race condition when multiple orders placed by a user are being processed at the same time, but only one would have been eligible as a check on the Redis attribute which stores the margin would not have allowed both the transactions.

Data Races in JavaScript?

天涯浪子 提交于 2019-12-02 04:23:34
Lets assume I run this piece of code. var score = 0; for (var i = 0; i < arbitrary_length; i++) { async_task(i, function() { score++; }); // increment callback function } In theory I understand that this presents a data race and two threads trying to increment at the same time may result in a single increment, however, nodejs(and javascript) are known to be single threaded. Am I guaranteed that the final value of score will be equal to arbitrary_length? Node uses an event loop. You can think of this as a queue. So we can assume, that your for loop puts the function() { score++; } callback

Possible race condition creating Structs in ColdFusion

◇◆丶佛笑我妖孽 提交于 2019-12-01 21:31:37
问题 I've been seeing intermittent errors in a couple of systems I've been working on, when using the same methodology (not the same code) leading me to believe the problem may be linked to creating and using structs in the same request. I'm wondering if it's possible there's a race condition? The scenario is this: We're on an e-commerce system, looking at a product, or in some cases a list of products. The code in question is designed to return the images associated with each product, in a struct

Javascript thread-handling and race-conditions

心不动则不痛 提交于 2019-12-01 19:29:05
问题 Lets asume I have a code like the following: var shared = 100; function workWithIt(){ shared += 100; } setTimeout(workWithIt, 500); setTimeout(workWithIt, 500); Ideally, this piece of code should add 200 to the variable shared , which is 300 afterwards. But, as I know from c , there can be some implications, if the operation += is split into multiple commands. Lets say, that this is the execution-order of the function: setTimeout() --> create Thread A setTimeout() --> create Thread B wait

Possible race condition creating Structs in ColdFusion

淺唱寂寞╮ 提交于 2019-12-01 18:38:16
I've been seeing intermittent errors in a couple of systems I've been working on, when using the same methodology (not the same code) leading me to believe the problem may be linked to creating and using structs in the same request. I'm wondering if it's possible there's a race condition? The scenario is this: We're on an e-commerce system, looking at a product, or in some cases a list of products. The code in question is designed to return the images associated with each product, in a struct that we can use for display of said images. At the beginning of the request, the code looks for

Javascript thread-handling and race-conditions

亡梦爱人 提交于 2019-12-01 18:37:38
Lets asume I have a code like the following: var shared = 100; function workWithIt(){ shared += 100; } setTimeout(workWithIt, 500); setTimeout(workWithIt, 500); Ideally, this piece of code should add 200 to the variable shared , which is 300 afterwards. But, as I know from c , there can be some implications, if the operation += is split into multiple commands. Lets say, that this is the execution-order of the function: setTimeout() --> create Thread A setTimeout() --> create Thread B wait 500ms **Thread A** | **Thread B** --------------------------------+--------------------------------- var

Race condition in android dlopen()?

浪尽此生 提交于 2019-12-01 18:25:41
My Android app has a simple "loader" NativeActivity with a very simple android_main() which only loads a different shared object and passes control to it: typedef void (*Tandroid_main)( android_app*); void android_main( android_app* state ) { void* glib = dlopen("libmain.so", RTLD_NOW); void* fmain = dlsym(glib, "android_main"); Tandroid_main libmain = (Tandroid_main)fmain; libmain(state) } This works well.. about half of the times. Other times it crashes since dlopen() fails and return NULL with errno=2 (No such file). Due to the strange inconsistency of this occurrence I suspected a timing

Race condition in android dlopen()?

帅比萌擦擦* 提交于 2019-12-01 17:39:46
问题 My Android app has a simple "loader" NativeActivity with a very simple android_main() which only loads a different shared object and passes control to it: typedef void (*Tandroid_main)( android_app*); void android_main( android_app* state ) { void* glib = dlopen("libmain.so", RTLD_NOW); void* fmain = dlsym(glib, "android_main"); Tandroid_main libmain = (Tandroid_main)fmain; libmain(state) } This works well.. about half of the times. Other times it crashes since dlopen() fails and return NULL

Segmentation Fault p_thread with a possible race condition

↘锁芯ラ 提交于 2019-12-01 14:24:05
Issue: I created a linked list of Child thread TIDS and want to wait on all the child tids to finish execution before I continue my main thread. Basically I have directory traversal (a directory is specified by the members of a given struct ). Every time I see a directory or file I create a new thread and put its threadID into the linked list. However when I traverse the linked list and call pthread_join I get a segmentation fault (core dumped) - I cannot understand why. I believe in may have to do with race condition but I am not sure. When I remove the pthread_join I no longer segfault

Semaphores and locks in MATLAB

眉间皱痕 提交于 2019-12-01 14:05:10
问题 I am working on a MATLAB project where I would like to have two instances of MATLAB running in parallel and sharing data. I will call these instances MAT_1 and MAT_2 . More specifically, the architecture of the system is: MAT_1 processes images sequentially, reading them one by one using imread , and outputs the result for each image using imwrite . MAT_2 reads the images output by MAT_1 using imread and outputs its result somewhere else. One of the problems I think I need to address is to