- 博客(29)
- 资源 (4)
- 收藏
- 关注
原创 Scalable Hazard Pointers
由于我对于Java并发库JUC的深入了解,一直以来有个想法,能不能把Java并发库移植到纯C语言环境下,并且在实现、使用方式上都与Java平台保持相当程度的相似性呢?纯C环境下内存模型与Java平台不一致?加上内存屏障(fence)或者lock指令就行。 C环境下缺少对象模型?无非是给每个数据块提供个*init方法(比如pthread_mutex_t的pthread_mutex_init,pthr...
2017-11-17 16:14:32
632
原创 并发编程中的一致性问题:ForkJoinPool调用shutdown的bug.(jdk8&jdk9)
ForkJoinPool调用shutdown从而终止整个并发执行框架。包括取消所有队列中已有的任务,终止所有的工作线程。
2017-09-16 15:58:30
3531
1
原创 Java多线程:内存可见性
Java中对于volatile变量,通俗点说可以把它看做多线程之间分享的共享内存,可见性是立即的。实际上它分成了两部分,volatile write和volatile read。由于Unsafe提供了getXXXVolatile和putXXXVolatile接口。所以这样一来Java中对于能够共享的变量,至少有四种访问方式:普通写、普通读、putXXXVolatile、getXXXVola
2017-07-01 03:19:22
966
原创 LockFreeHashMap:无阻塞代码技巧
10年前,cliff click博士就为关联数据结构ConcurrentHashMap给出了一个采用open Address的无阻塞实现(NonBlockingHashMap)。其中为了减少线程之间执行顺序的依赖而采用的算法充满技巧性。这个算法宣称是无锁,几乎可以保证任何时候停止某个特定线程都不会导致整体进程的停止(极端情况下,这一点还是会阻塞整个进程的)。本文尝试详细地分析其中的完整代码,从
2017-06-30 17:01:21
1262
原创 JVM:锁实现(synchronized&JSR166)行为分析和相关源码
JVM中有这样一段注释:// The base-class, PlatformEvent, is platform-specific while the ParkEvent is// platform-independent. PlatformEvent provides park(), unpark(), etc., and// is abstract -- that is, a Pl
2017-06-28 11:35:46
2854
1
原创 Java实现临界区:经典并发控制回顾
只要有一定的内存order保证,不通过比较并交换(CAS)那些需要硬件支持的原子操作,能不能实现一个互斥的临界区?答案是:能。计算机先驱djkstra,50多年前的这篇经典paper中就提出了解决方案。并且自这以后开启了如何通过一般编程语言实现并发控制的 研究。这里的假设我们有N个线程,代表序号分别为1-N,一个公共变量k用于辅助指示当前占有临界区的线程。临界区是critical
2017-06-28 11:31:48
1359
原创 pthread_mutex_unlock实现
我们接着看pthread_mutex_unlock的实现,会发现它跟pthread_mutex_lock形式差不多,并且底层调用futex换乐FUTEX_WAKE而已。直接贴路径代码:int__pthread_mutex_unlock (pthread_mutex_t *mutex){ return __pthread_mutex_unlock_usercnt (mutex, 1)
2017-06-20 16:30:23
6841
原创 pthread_mutex_lock实现
void 4 __lll_lock_wait (int *futex, int private) 5 { 6 if (*futex == 2) 7 lll_futex_wait (futex, 2, private); /* Wait if *futex == 2. */ 8 9 while (atomic_exchange_acq (futex, 2) != 0)10 lll_futex_wait (futex, 2, private); /* Wait if *
2017-06-20 15:58:25
5836
原创 Java Thread&Concurrency(1): 深入理解Fork-Join并发执行框架
public void execute(Runnable task) { if (task == null) throw new NullPointerException(); ForkJoinTask job; if (task instanceof ForkJoinTask) // avoid re-wrap
2014-07-29 13:28:17
3108
原创 Java Thread&Concurrency(16): 深入理解ArrayBlockingQueue及其实现原理
ArrayBlockingQueue
2014-07-29 12:32:44
716
原创 Java Thread&Concurrency(15): 深入理解ScheduledThreadPoolExecutor及其实现原理
ScheduledExecutorService通过继承ExecutorService提供了
2014-07-28 23:43:31
1844
原创 Java Thread&Concurrency(13): 深入理解ConcurrentLinkedQueue及其实现原理
ConcurrentLinkedQueue
2014-07-22 12:51:35
594
原创 Java Thread&Concurrency(11): 深入理解ThreadPoolExecutor及其实现原理
/** * Executes the given task sometime in the future. The task * may execute in a new thread or in an existing pooled thread. * * If the task cannot be submitted for execution, ei
2014-06-12 16:41:35
759
原创 Java Thread&Concurrency(10): 深入理解ThreadLocal及其实现原理
/** * Returns the value in the current thread's copy of this * thread-local variable. If the variable has no value for the * current thread, it is first initialized to the value return
2014-06-12 16:35:24
992
原创 Java Thread&Concurrency(9): 深入理解StampedLock及其实现原理
/** * Non-exclusively acquires the lock, blocking if necessary * until available. * * @return a stamp that can be used to unlock or convert mode */ public long readLock()
2014-06-12 16:30:02
3959
原创 Java Thread&Concurrency(8): 深入理解CompletionService接口及其实现
/** * FutureTask extension to enqueue upon completion */ private class QueueingFuture extends FutureTask { QueueingFuture(RunnableFuture task) { super(task, null);
2014-06-12 16:27:54
787
原创 Java Thread&Concurrency(7): 深入理解Callable/Future(FutureTask)接口及其实现
public void run() { if (state != NEW || !UNSAFE.compareAndSwapObject(this, runnerOffset, null, Thread.currentThread())) return;
2014-06-12 16:25:38
907
原创 Java Thread&Concurrency(5): 深入理解Phaser实现原理
public int arriveAndAwaitAdvance() { // Specialization of doArrive+awaitAdvance eliminating some reads/paths final Phaser root = this.root; for (;;) { long s = (roo
2014-06-12 16:10:44
1914
原创 Java Thread&Concurrency(4): 深入理解Exchanger实现原理
/** * Exchange function used until arenas enabled. See above for explanation. * * @param item the item to exchange * @param timed true if the wait is timed * @param ns if time
2014-06-12 16:05:21
2674
原创 Java Thread&Concurrency(3): 深入理解SynchronousQueue实现原理
/** * Puts or takes an item. */ @SuppressWarnings("unchecked") E transfer(E e, boolean timed, long nanos) { /* Basic algorithm is to loop trying to take e
2014-06-12 15:58:35
969
原创 Java Thread&Concurrency(2): 深入理解ConcurrentSkipListMap实现原理
/** * Main insertion method. Adds element if not present, or * replaces value if present and onlyIfAbsent is false. * @param key the key * @param value the value that must be asso
2014-06-12 13:35:07
923
Bug:LinkedTransferQueue的数据暂失和CPU爆满以及修复
前几天读LinkedTransferQueue(以下简称ltq)的源码,想加深下对松弛型双重队列的理解,无意中发现了这个问题:),经过仔细检查后确认了这是个bug,存在于JDK1.7.0_40和刚发布的JDK8中,去google和oracle官方似乎也没有搜索到这个问题。重现bug:先来重现下这个bug,由于对并发线程的执行顺序预先不能做任何假设,所以很可能根本就不存在所谓的重现错误的“测...
2014-04-08 13:09:29
175
原创 Bug:LinkedTransferQueue的数据暂失和CPU爆满
前几天读LinkedTransferQueue(以下简称ltq)的源码,想加深下对松弛型双重队列的理解,无意中发现了这个问题:),经过仔细检查后确认了这是个bug,存在于JDK1.7.0_40和刚发布的JDK8中,去google和oracle官方似乎也没有搜索到这个问题。重现bug:先来重现下这个bug,由于对并发线程的执行顺序预先不能做任何假设,所以很可能根本就不存在所谓的重现错误的“测
2014-04-08 12:57:03
1139
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人