synchronization

Getting CodeMirror to follow a TextArea

▼魔方 西西 提交于 2019-12-04 23:15:26
问题 How can I get CodeMirror to sync with a TextArea, so that the cursor position, selection & data stay the same on the both of them? I'm using CodeMirror with MobWrite. CodeMirror only uses a textArea to read input & MobWrite can handle the selection, etc over a given TextArea, the problem is to get CodeMirror to sync with a TextArea. 回答1: Extended the ModWrite code to support CodeMirror & it works like a charm. It can also be found on GitHub. Details on the CodeMirror Group. Code dumped below

Why does the acquire() method in Semaphores not have to be synchronized?

六眼飞鱼酱① 提交于 2019-12-04 23:11:13
问题 I am getting into Semaphores in Java and was reading this article http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Semaphore.html . The only thing I don't get is why the acquire() method is not used in a synchronized context. Looking at the example from the above webiste: They create a semaphore: private Semaphore semaphore = new Semaphore(100); and get a permit just like this: semaphore.acquire(); Now, wouldn't it be possible that two or more threads try to acquire() at the

Is the Win32 registry thread-safe?

荒凉一梦 提交于 2019-12-04 22:45:29
If I have two processes accessing a given registry key (e.g. HKLM ), should I wrap the the logic in a mutex? The registry will make sure the actions are atomic, so you don't have to synchronize it yourself. However, if you have multiple processes / threads accessing the registry at the same time, it doesn't make any guarantees about which happens first. Only that you won't get garbled data. Edit: Further reading, see The inability to lock someone out of the registry is a feature, not a bug . As others have mentioned, individual operations are atomic. If you need to make a larger set of

Can rsync support One to Many syncing?

泄露秘密 提交于 2019-12-04 21:06:59
问题 Can I sync changes from a "model" site that I work on, across hundreds of sites on the SAME server using rsync ? I would be updating common template files and JS scripts. If possible how would I set this up? (I'm on a Hostgator Dedicated server, running Apache) 回答1: Read my extended answer for the edited question below. The most trivial and naive approach would probably to set up a script that just runs rsync for every server you want to synchronize. This is fine in most cases, but I don't

is volatile of no use on x86 processors

不想你离开。 提交于 2019-12-04 20:54:22
I read somewhere that x86 processors have cache coherency and can sync the value of fields across multiple cores anyway on each write. Does that mean that we can code without using the 'volatile' keywoard in java if we plan on running only on x86 processors? Update: Ok assuming that we leave out the issue of instruction reordering, can we assume that the issue of an assignment to a non-volatile field not being visible across cores is not present on x86 processors? No -- the volatile keyword has more implications than just cache coherency; it also places restrictions on what the runtime can and

Spring @Transactional concurrency

我们两清 提交于 2019-12-04 19:26:23
class MyService { public void a() { synchronized(somekey) { b(); } } @Transactional(propagation = Propagation.REQUIRES_NEW) public void b() { ...do DB works... } } My aim is 1 - get the key 2 - start transaction 3 - commit transaction 4 - release the key When i call a() method from outside, transaction doesn't work. Any suggestions ? Thanks. Unless you're using code weaving, this can't work. The default way Spring handles transactions is through AOP proxies . The call to a transactional method goes like this: caller --> ProxyClass.a() --> YourClass.a() If you call another method on the same

Semaphore Vs Mutex

若如初见. 提交于 2019-12-04 19:00:51
I was reading a bit of Mutex and semaphore. I have piece of code int func() { i++; return i; } i is declared somewhere outside as a global variable. If i create counting semaphore with count as 3 won't it have a race condition? does that mean i should be using a binary semaphore or a Mutex in this case ? Can somebody give me some practical senarios where Mutex, critical section and semaphores can be used. probably i read lot. At the end i am a bit confused now. Can somebody clear the thought. P.S: I have understood that primary diff between mutex and binary semaphore is the ownership. and

Java: how volatile guarantee visibility of “data” in this piece of code?

本秂侑毒 提交于 2019-12-04 18:56:36
Class Future { private volatile boolean ready; private Object data; public Object get() { if(!ready) return null; return data; } public synchronized void setOnce(Object o) { if(ready) throw...; data = o; ready = true; } } It said "if a thread reads data, there is a happens-before edge from write to read of that guarantees visibility of data" I know from my learning: volatile ensures that every read/write will be in the memory instead of only in cache or registers; volatile ensures reorder: that is, in setOnce() method data = o can only be scheduled after if(ready) throw..., and before ready =

Is Java ArrayList / String / atomic variable reading thread safe?

瘦欲@ 提交于 2019-12-04 18:37:34
问题 I've been mulling this over & reading but can find an absolute authoritative answer. I have several deep data structures made up of objects containing ArrayLists, Strings & primitive values. I can guarantee that the data in these structures will not change (no thread will ever make structural changes to lists, change references, change primitives). I'm wondering if reading data in these structures is thread safe; i.e. is it safe to recursively read variables from the objects, iterate the

What is meant by “fast-path” uncontended synchronization?

爷,独闯天下 提交于 2019-12-04 18:19:15
问题 From the Performance and Scalability chapter of the JCIP book: The synchronized mechanism is optimized for the uncontended case(volatile is always uncontended), and at this writing, the performance cost of a "fast-path" uncontended synchronization ranges from 20 to 250 clock cycles for most systems. What does the author mean by fast-path uncontended synchronization here? 回答1: I'm not familiar with the topic of the book, but in general a “fast path” is a specific possible control flow branch