concurrency

Reading a stale value after a newer value was read [duplicate]

旧街凉风 提交于 2021-02-08 02:37:33
问题 This question already has answers here : Reordering of reads (2 answers) Closed 2 months ago . Consider this example. We're having: int var = 0; Thread A: System.out.println(var); System.out.println(var); Thread B: var = 1; The threads run concurrently. Is the following output possible? 1 0 That is, the original value is read after the new value was read. The var isn't volatile. My gut feeling is that it's not possible. 回答1: You are using System.out.println that internally does a synchronized

Singleton Azure function running as separate instances

谁说胖子不能爱 提交于 2021-02-07 23:01:45
问题 We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end. We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be

Force a migration of a cache line to another core

天涯浪子 提交于 2021-02-07 22:43:21
问题 In C++ (using any of the low level intrinsics available on the platform) for x86 hardware (say Intel Skylake for example), is it possible to send a cacheline to another core without forcing the thread on that core to load the line explicitly? My usecase is in a concurrent data-structure. In this, for some cases a core goes through some places in memory that might be owned by some other core(s) while probing for spots. The threads on those cores are typically are blocked on a condition

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 captured variables?

久未见 提交于 2021-02-07 13:17:25
问题 I'm having a problem with foreach(var category in categories) { foreach(var word in words) { var waitCallback = new WaitCallback(state => { DoSomething(word, category); }); ThreadPool.QueueUserWorkItem(waitCallback); } } When the DoSomething gets executed, it receives the latest value for each captured variable instead of the value I desired. I can imagine a solution for this, but it imagine you guys can come up with better solutions 回答1: The canonical way to solve this is to copy the values

Java Thread Start-Stop-Start on same button click

巧了我就是萌 提交于 2021-02-07 10:33:40
问题 I am creating a simple java program with a GUI built with the help of window builder. The GUI consists of just a button. On button click,start a thread that will print to the random number infinitely until it is stopped by clicking the same button again. Here is my code LoopTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class LoopTest extends JFrame implements ActionListener {//****** private JButton startB, stopB; private JTextArea oa; Start sta; public

How this java program keeps running even after main function exits?

做~自己de王妃 提交于 2021-02-07 10:24:41
问题 I am trying to learn the concurrency API of java. Below is a sample program. class WaitTest { public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException { ExecutorService executorService = null; try { executorService = Executors.newSingleThreadExecutor(); Future<?> future = executorService.submit(() -> { for (int i = 0; i < 100; i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Printing "

How to fix 508 Resource Limit is reached in PHP MySQL

限于喜欢 提交于 2021-02-07 10:01:07
问题 How to fix 508 Resource Limit is reached in PHP MySQL My website is developed in PHP with MySQL and javascript ajax. My website is blocked , how to rectify immediately in this problem, anyone help me quickly please. but am got bellow error, Resource Limit Is Reached The website is temporarily unable to service your request as it exceeded resource limit. Please try again later. Apache/2.4.12 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 Server at domain.co.in Port 80 What is concurrent

Does Amazon S3 guarantee write ordering?

纵饮孤独 提交于 2021-02-07 07:23:15
问题 Amazon S3 provides an "eventual consistency" model, where data you store is eventually visible to all clients. I can't find any official information as to whether write ordering is guaranteed or not. This is fundamentally important if you are building an architecture where a client might want to read data right after someone else stored it. If write ordering is preserved, I can easily check whether the data is complete by having the writer store a guard (say, a special key) and the end of the