multithreading

Does memory fencing blocks threads in multi-core CPUs?

蓝咒 提交于 2020-12-29 13:54:34
问题 I was reading the Intel instruction set guide 64-ia-32 guide to get an idea on memory fences. My question is that for an example with SFENCE, in order to make sure that all store operations are globally visible, does the multi-core CPU parks all the threads even running on other cores till the cache coherence achieved ? 回答1: Barriers don't make other threads/cores wait. They make some operations in the current thread wait , depending on what kind of barrier it is. Out-of-order execution of

Does memory fencing blocks threads in multi-core CPUs?

六月ゝ 毕业季﹏ 提交于 2020-12-29 13:52:02
问题 I was reading the Intel instruction set guide 64-ia-32 guide to get an idea on memory fences. My question is that for an example with SFENCE, in order to make sure that all store operations are globally visible, does the multi-core CPU parks all the threads even running on other cores till the cache coherence achieved ? 回答1: Barriers don't make other threads/cores wait. They make some operations in the current thread wait , depending on what kind of barrier it is. Out-of-order execution of

Does memory fencing blocks threads in multi-core CPUs?

旧时模样 提交于 2020-12-29 13:52:00
问题 I was reading the Intel instruction set guide 64-ia-32 guide to get an idea on memory fences. My question is that for an example with SFENCE, in order to make sure that all store operations are globally visible, does the multi-core CPU parks all the threads even running on other cores till the cache coherence achieved ? 回答1: Barriers don't make other threads/cores wait. They make some operations in the current thread wait , depending on what kind of barrier it is. Out-of-order execution of

Does memory fencing blocks threads in multi-core CPUs?

徘徊边缘 提交于 2020-12-29 13:51:09
问题 I was reading the Intel instruction set guide 64-ia-32 guide to get an idea on memory fences. My question is that for an example with SFENCE, in order to make sure that all store operations are globally visible, does the multi-core CPU parks all the threads even running on other cores till the cache coherence achieved ? 回答1: Barriers don't make other threads/cores wait. They make some operations in the current thread wait , depending on what kind of barrier it is. Out-of-order execution of

Django ORM leaks connections when using ThreadPoolExecutor

女生的网名这么多〃 提交于 2020-12-29 10:44:46
问题 I'm using ThreadPoolExecutor to speed up data processing. The problem is that the thread pool creates new database connections and Django doesn't close them. I do have CONN_MAX_AGE in settings.py and I already tried to call django.db.close_old_connections() . Here is a code example: def compute(job): result = FooModel.objects.filter(...).aggregate(...) return BarModel.objects.create(result) def process(dataset): thread_pool = ThreadPoolExecutor(max_workers=20) futures = [] for job in dataset:

Is AddOrUpdate thread safe in ConcurrentDictionary?

杀马特。学长 韩版系。学妹 提交于 2020-12-29 06:10:38
问题 I tried to use AddOrUpdate method in ConcurrentDictionary. From the "Remarks" section on this page https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx. it says "However, delegates for these methods are called outside the locks to avoid the problems that can arise from executing unknown code under a lock. Therefore, the code executed by these delegates is not subject to the atomicity of the operation." So I am not sure whether it is thread safe. I have one case, if the key is not

Is AddOrUpdate thread safe in ConcurrentDictionary?

和自甴很熟 提交于 2020-12-29 06:08:40
问题 I tried to use AddOrUpdate method in ConcurrentDictionary. From the "Remarks" section on this page https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx. it says "However, delegates for these methods are called outside the locks to avoid the problems that can arise from executing unknown code under a lock. Therefore, the code executed by these delegates is not subject to the atomicity of the operation." So I am not sure whether it is thread safe. I have one case, if the key is not

Is AddOrUpdate thread safe in ConcurrentDictionary?

那年仲夏 提交于 2020-12-29 06:08:32
问题 I tried to use AddOrUpdate method in ConcurrentDictionary. From the "Remarks" section on this page https://msdn.microsoft.com/en-us/library/dd287191(v=vs.110).aspx. it says "However, delegates for these methods are called outside the locks to avoid the problems that can arise from executing unknown code under a lock. Therefore, the code executed by these delegates is not subject to the atomicity of the operation." So I am not sure whether it is thread safe. I have one case, if the key is not

How to get Executor for main thread on API level < 28

自闭症网瘾萝莉.ら 提交于 2020-12-29 05:31:05
问题 On API level 28(Pie) a new method is introduced in the Context class to get Executor for the main thread getMainExecutor(). How to get this executor on API level below 28? 回答1: You can use (in activity for example): ContextCompat.getMainExecutor(this); https://developer.android.com/reference/androidx/core/content/ContextCompat.html#getMainExecutor(android.content.Context) 回答2: You can use code snippet from retrofit https://github.com/square/retrofit/blob/master/retrofit/src/main/java

Does object construction guarantee in practice that all threads see non-final fields initialized?

自闭症网瘾萝莉.ら 提交于 2020-12-29 04:00:55
问题 The Java memory model guarantees a happens-before relationship between an object's construction and finalizer: There is a happens-before edge from the end of a constructor of an object to the start of a finalizer (§12.6) for that object. As well as the constructor and the initialization of final fields: An object is considered to be completely initialized when its constructor finishes. A thread that can only see a reference to an object after that object has been completely initialized is