concurrency

Thread::yield vs Thread::onSpinWait

六月ゝ 毕业季﹏ 提交于 2021-02-18 05:33:15
问题 Well the title basically says it all, with the small addition that I would really like to know when to use them. And it might be simple enough - I've read the documentation for them both, still can't tell the difference much. There are answers like this here that basically say: Yielding also was useful for busy waiting... I can't agree much with them for the simple reason that ForkJoinPool uses Thread::yield internally and that is a pretty recent addition in the jdk world. The thing that

Why is reference assignment atomic in Java?

拟墨画扇 提交于 2021-02-17 19:13:38
问题 As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn't use atomic pointers internally to model this, since otherwise there would be no need for Atomic References. So my questions are: Is atomic reference assignment in the "specs" of java/Scala and guaranteed to happen or is it just a happy coincidence that it is that way most times ? Is atomic reference assignment implied for any language that compiles to the JVM's bytecode (e.g. clojure, Groovy, JRuby,

Why is reference assignment atomic in Java?

Deadly 提交于 2021-02-17 19:11:30
问题 As far as I know reference assignment is atomic in a 64 bit JVM. Now, I assume the jvm doesn't use atomic pointers internally to model this, since otherwise there would be no need for Atomic References. So my questions are: Is atomic reference assignment in the "specs" of java/Scala and guaranteed to happen or is it just a happy coincidence that it is that way most times ? Is atomic reference assignment implied for any language that compiles to the JVM's bytecode (e.g. clojure, Groovy, JRuby,

PHP and Concurrency

不羁的心 提交于 2021-02-17 16:40:35
问题 I've been doing some web development work in PHP recently which has led me to study up on the language in general. So far I have not needed to use it to interact with a database, but I know it provides a lot of convenient functions for doing so. Although I know basic SQL and have worked with basic manipulation of data in a database, I don't understand how web developers who base their websites around PHP/Javascript/SQL are able to manage users modifying the same data at the same time. For

PHP and Concurrency

荒凉一梦 提交于 2021-02-17 16:40:18
问题 I've been doing some web development work in PHP recently which has led me to study up on the language in general. So far I have not needed to use it to interact with a database, but I know it provides a lot of convenient functions for doing so. Although I know basic SQL and have worked with basic manipulation of data in a database, I don't understand how web developers who base their websites around PHP/Javascript/SQL are able to manage users modifying the same data at the same time. For

PHP and Concurrency

≯℡__Kan透↙ 提交于 2021-02-17 16:38:34
问题 I've been doing some web development work in PHP recently which has led me to study up on the language in general. So far I have not needed to use it to interact with a database, but I know it provides a lot of convenient functions for doing so. Although I know basic SQL and have worked with basic manipulation of data in a database, I don't understand how web developers who base their websites around PHP/Javascript/SQL are able to manage users modifying the same data at the same time. For

Semaphore - What is the use of initial count?

拟墨画扇 提交于 2021-02-17 07:33:12
问题 http://msdn.microsoft.com/en-us/library/system.threading.semaphoreslim.aspx To create a semaphore, I need to provide an initial count and maximum count. MSDN states that an initial count is - The initial number of requests for the semaphore that can be granted concurrently. While it states that maximum count is The maximum number of requests for the semaphore that can be granted concurrently. I can understand that the maximum count is the maximum number of threads that can access a resource

Do I need to clean up Thread objects in Java?

怎甘沉沦 提交于 2021-02-17 03:27:13
问题 In my Java application I have a Runnable such as: this.runner = new Runnable({ @Override public void run() { // do something that takes roughly 5 seconds. } }); I need to run this roughly every 30 seconds (although this can vary) in a separate thread. The nature of the code is such that I can run it and forget about it (whether it succeeds or fails). I do this as follows as a single line of code in my application: (new Thread(this.runner)).start() Now, this works fine. However, I'm wondering

What is the differene between concurrency and multithreading?

蹲街弑〆低调 提交于 2021-02-16 14:40:15
问题 What is the differene between concurrency and multithreading? Is concurrency only possible in multicore cpu? can anybody explain it with an example? 回答1: What is the differene between concurrency and multithreading? Concurrency describes the way in which processes run. They are either sequential (one after another), concurrent (able to make progress "at the same time" although not necessarily at the same instant), or parallel (they happen simultaneously). Multi-threading is a technique which

double check locking without volatile (but with VarHandle release/acquire)

橙三吉。 提交于 2021-02-13 12:14:31
问题 The question is rather easy, in a way. Suppose I have this class: static class Singleton { } And I want to provide a singleton factory for it. I can do the (probably) obvious. I am not going to mention the enum possibility or any other, as they are of no interest to me. static final class SingletonFactory { private static volatile Singleton singleton; public static Singleton getSingleton() { if (singleton == null) { // volatile read synchronized (SingletonFactory.class) { if (singleton ==