race-condition

Problems with race conditions on ConcurrentHashMap

◇◆丶佛笑我妖孽 提交于 2021-02-10 23:54:04
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

Problems with race conditions on ConcurrentHashMap

ⅰ亾dé卋堺 提交于 2021-02-10 23:48:27
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

Problems with race conditions on ConcurrentHashMap

自古美人都是妖i 提交于 2021-02-10 23:47:45
问题 I got a multithreaded application in which n threads write to an ConcurrentHashMap . Another n Threads read from that Map and copy its Value to a copy List. After that the original List is removed from the map. For some reason I always get a ConcurrentModificationException . I even tried to create my own lock mechanism with a volatile boolean, but it won't work. When using Google Guava with Lists.newLinkedList() i get a ConcurrentModificationException . When using the StandardWay new

How to avoid two concurrent API requests breaking the logic behind document validation?

♀尐吖头ヾ 提交于 2021-02-10 18:56:21
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);

How to avoid two concurrent API requests breaking the logic behind document validation?

非 Y 不嫁゛ 提交于 2021-02-10 18:54:43
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);

How to avoid two concurrent API requests breaking the logic behind document validation?

不问归期 提交于 2021-02-10 18:54:34
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);

How to avoid two concurrent API requests breaking the logic behind document validation?

纵饮孤独 提交于 2021-02-10 18:53:45
问题 I have an API that in order to insert a new item it needs to be validated. The validation basically is a type validator( string , number , Date , e.t.c) and queries the database that checks if the "user" has an "item" in the same date, which if it does the validation is unsuccessful. Pseudocode goes like this: const Item = require("./models/item"); function post(newDoc){ let errors = await checkForDocErrors(newDoc) if (errors) { throw errors; } let itemCreated = await Item.create(newDoc);

Why would 'deleting' nodes in this lock-free stack class would cause race condition?

佐手、 提交于 2021-02-07 18:18:21
问题 In the book titled "C++ Concurrency in Action" by Anthony Williams, in Section 7.2.1, a lock-free stack implementation is listed: template <typename T> class lock_free_stack { struct node { shared_ptr<T> data_; node* next_; node(const T& data) : data_(make_shared(data)) {} }; atomic<node*> head_; public: void push(const T& data) { node* new_node = new node(data); new_node->next_ = head_.load(); while(!head.compare_exchange_weak(new_node->next_, new_node)); } shared_ptr<T> pop() { node* old

Why would 'deleting' nodes in this lock-free stack class would cause race condition?

浪子不回头ぞ 提交于 2021-02-07 18:18:08
问题 In the book titled "C++ Concurrency in Action" by Anthony Williams, in Section 7.2.1, a lock-free stack implementation is listed: template <typename T> class lock_free_stack { struct node { shared_ptr<T> data_; node* next_; node(const T& data) : data_(make_shared(data)) {} }; atomic<node*> head_; public: void push(const T& data) { node* new_node = new node(data); new_node->next_ = head_.load(); while(!head.compare_exchange_weak(new_node->next_, new_node)); } shared_ptr<T> pop() { node* old

How to avoid race condition?

独自空忆成欢 提交于 2021-02-05 08:59:05
问题 I am make random 1:1 chat app with Flutter and Firestore. But I have race condition when I am connect second user to chat. This my client app code for add second user to Firestore (first user is already add to Firestore document): await chatRoomReference.setData({ ‘secondUserUID': uid, }); When second user tap to chat I am remove option to enter this chatroom from all client UI. But is possible that if third user tap to chat at same time (before UI get update from stream) he will also be add