synchronization

Can synchronization be treated as an aspect in AOP

一个人想着一个人 提交于 2019-12-10 14:31:54
问题 I understand that in AOP any cross cutting concerns such as Logging, transaction etc can be treated as an aspect and most of the AOP frameworks very well support these kind of cross-cutting concerns. My question is, Can Synchronization be treated as a crosscutting concern ? If yes, are there any existing libraries (including AspectJ and Spring AOP) which support this functionality out of box ? I searched but could not find many examples. I came across some restricted research papers (1,2)

Logging strategy vs. performance

我的梦境 提交于 2019-12-10 14:13:49
问题 I'm developing a web application that has to support lots of simultaneous requests, and I'd like to keep it fast enough. I have now to implement a logging strategy, I'm gonna use log4net, but ... what and how should I log? I mean: How logging impacts in performance? is it possible/recomendable logging using async calls? Is better use a text file or a database? Is it possible to do it conditional? for example, default log to the database, and if it fails, the switch to a text file. What about

Easier way to synchronize 2 threads in Java?

懵懂的女人 提交于 2019-12-10 14:08:45
问题 I wan't to be sure that some piece of my code within the main thread will be executed after some piece of code executed withing the secondary thread. Here's what I got: final Object lock = new Object(); final Thread t = new Thread(new Runnable() { public void run() { synchronized(lock) { System.out.println("qwerty"); lock.notify(); } } }); synchronized(lock) { t.start(); lock.wait(); } System.out.println("absolutely sure, qwerty is above"); Is it correct solution? Any shorter ways to do the

What is the name of this locking technique?

旧时模样 提交于 2019-12-10 14:03:11
问题 I've got a gigantic Trove map and a method that I need to call very often from multiple threads. Most of the time this method shall return true . The threads are doing heavy number crunching and I noticed that there was some contention due to the following method (it's just an example, my actual code is bit different): synchronized boolean containsSpecial() { return troveMap.contains(key); } Note that it's an "append only" map: once a key is added, is stays in there forever (which is

Synchronizing access to Immutable Integer object

一个人想着一个人 提交于 2019-12-10 13:50:01
问题 Code snippet - 1 class RequestObject implements Runnable { private static Integer nRequests = 0; @Override public void run() { synchronized (nRequests) { nRequests++; } } } Code snippet - 2 class RequestObject implements Runnable { private static Integer nRequests = 0; private static Object lock = new Object(); @Override public void run() { synchronized (lock) { nRequests++; } } } While the second code snippet is working fine without causing any race conditions, the first one isn't successful

PHP-based database models that sync with database?

爷,独闯天下 提交于 2019-12-10 13:39:50
问题 Django models are really cool because you define all your models/tables right in the code, and then sync it with the database. That way when you go to update your production server, you just run the migration/sync script and you can't forget to update any tables. The project I'm working on now though isn't Django or Python-based, it's written in PHP, and all the queries are written in straight SQL (no ORM). We've got many databases that need to be updated every time we make a change. Right

Fair semaphore in python

好久不见. 提交于 2019-12-10 13:24:37
问题 Is it possible to have a fair semaphore in python, one that guarantees that blocking threads are unblocked in the order they call acquire() ? 回答1: You might have to build one from other moving parts. For example, create a Queue.Queue() to which each listener posts a brand-new Event() on which it then waits. When it is time to wake up one of the waiting threads, pop off the item on the queue that has been waiting longest — it will be one of those event objects — and release the thread through

How does ThreadLocal usage reduce reusability

白昼怎懂夜的黑 提交于 2019-12-10 12:59:07
问题 The well acclaimed book JCIP says this about ThreadLocal usage : It is easy to abuse ThreadLocal by treating its thread confinement property as a license to use global variables or as a means of creating "hidden" method arguments. Thread-local variables can detract from reusability and introduce hidden couplings among classes, and should therefore be used with care. What does it mean by saying that Thread-local variables can reduce reusability and introduce hidden couplings among classes? 回答1

Vulkan: ordering image memory barriers in multiple command buffers

馋奶兔 提交于 2019-12-10 12:54:33
问题 For resource transitions, you need to know the 'before' and 'after' VkImageLayout of the resource (eg. in the VkImageMemoryBarrier passed to vkCmdPipelineBarrier ). Vulkan does not guarantee any ordering of execution of command buffers, unless explicitly stated in the API documentation (from this answer). However, vkCmdPipelineBarrier does explicitly say that it creates a dependency between commands in the command buffer, before and after the call. So it is possible to 'know' the layout of an

How can I read from the pinned (lock-page) RAM, and not from the CPU cache (use DMA zero-copy with GPU)?

孤者浪人 提交于 2019-12-10 12:21:13
问题 If I use DMA for RAM <-> GPU on CUDA C++, How can I be sure that the memory will be read from the pinned (lock-page) RAM, and not from the CPU cache? After all, with DMA, the CPU does not know anything about the fact that someone changed the memory and about the need to synchronize the CPU (Cache<->RAM). And as far as I know, std :: memory_barier () from C + +11 does not help with DMA and will not read from RAM, but only will result in compliance between the caches L1/L2/L3. Furthermore, in