å ±æã¡ã¢ãªã¢ãã«
Shared-State concurrency.
ãã¶ãæãã¡ãžã£ãŒãªäžŠåããã°ã©ãã³ã°ãã©ãã€ã .
å ±æã¡ã¢ãªã¢ãã«ã®åºç€æŠå¿µ
ðå ±æã¡ã¢ãª
è€æ°ã®ããã°ã©ã ãåæ䞊è¡çã«ã¢ã¯ã»ã¹ããã¡ã¢ãªé å.
ããã°ã©ã éã§æ å ±ãããåãããããã®å¹ççãªæ段.
æä»å¶åŸ¡
Mutual exclusion locks.
define a âcritical sectionâ that can only be executed by one thread at a time
éã«èšãã°, å ±æã¡ã¢ãªã䜿ããªãã¢ãã«ãªãã°æä»å¶åŸ¡ããããããªããŠãããšããå©ç¹ããã.
ãªãšã³ãã©ã³ã
Reentrant.
ããã°ã©ã ããµãã«ãŒãã³ã, å®è¡ã®éäžã§å²ã蟌ãŸã, ãã®å®è¡ãå®äºããåã«åã³åŒã³åºããå®è¡ãããŠãå®å šã ãšããæ§è³ª.
è€æ°ã®ã¹ã¬ããããåæã«åŒã³åºãããŠãæ£ããåäœããé¢æ°.
ref. ãªãšã³ãã©ã³ã - Wikipedia
ã¹ãã³ããã¯
Spin Lock
ã¹ã¬ãããããã¯ãç²åŸã§ãããŸã§åçŽã«ã«ãŒã (ã¹ãã³)ããŠå®æçã«ããã¯ããã§ãã¯ããªããåŸ ã€æ¹åŒ.
ref. ã¹ãã³ãã㯠- Wikipedia
åå ¥å¯èœããã¯
åå ¥å¯èœããã¯, Reentrant Lock, Sleep Lock.
Android API: ReentrantLock | Android Developers
A reentrant mutual exclusion lock that extends the built-in monitor lock capabilities.
ReadWriteLock
Readers-Writerlock, ãšããããã.
WriteLock Improves performance when resources are read much more often than written.
It allows multiple threads to read a certain resource, but only one to write it, at a time.
ref. Read / Write Locks in Java
ã»ããã©
䞊åããã°ã©ãã³ã°ç°å¢ã§ã®è€æ°ã®ããã»ã¹ãå ±æããè³æºã«ã¢ã¯ã»ã¹ããã®ãå¶åŸ¡ããéã®åçŽã ã䟿å©ãªæœè±¡åãæäŸããå€æ°ãŸãã¯æœè±¡ããŒã¿å.
A non-negative integer that controls the access of multiple threads to a limited number of shared resources
A semaphore can be atomically incremented & decremented to control access to a shared resource
èªæºã¯, è æšåŒä¿¡å·æ©.
ã«ãŠã³ãã£ã³ã°ã»ããã©
Counting Semaphores. ä»»æåã®è³æºãæ±ãã»ããã©.
ãã€ããªã»ããã©
Binary Semaphores.
å€ã 0 ãš 1 ã«å¶éãããŠãã (ããã¯/ ã¢ã³ããã¯, 䜿çšå¯èœ/ 䜿çšäžå¯ã®æå³ããã) ã»ããã©.
ãã¥ãŒããã¯ã¹ãšã.
Condition Value
æ¡ä»¶å€æ°. UNIX ã®çšèª.
ãã¥ãŒããã¯ã¹ãšäžç·ã«äœ¿çšã, ã¹ã¬ããããããã¯ããŠå¥ã®ã¹ã¬ããããã®ã·ã°ãã«ãåŸ ããã. éç¥ãããããšããã€ã³ã.
Block thread (s) until some condition (s) becomes true
-
wait
-
signal
-
signalAll
-
cf. ðããŒã¿ãããŒå€æ°ã¯èšèªã¬ãã«ã§ãµããŒããããŠãã䞊è¡æ©æ§.
-
refs. Guarded suspension
ConditionObject (Java)
Java ã§ã¯, ConditionObject ãšããŠæäŸããã.
AbstractQueuedSynchronizer.ConditionObject (Java Platform SE 6)
Barrier
ä»ã®ã¹ã¬ãããããå°ç¹ã§ãŸã¡åãããŠ, äžåºŠã«ãããããš. 競銬ã®ã¹ã¿ãŒãããŒã®ãããªã€ã¡ãŒãž.
ãŸãã¯, æ è¡ã®ãã¢ãŒã¬ã€ã. éåæéã決ããããŠããŠã.
CountDownLatch (Java)
Allows one or more threads to wait until a set of operations being performed in other threads complete
CountDownLatch (Java Platform SE 6)
References
- Concurrency Utilities ã䜿ã£ã䞊ååŠçã»ãã«ãã¹ã¬ããã®ãããã - argius note
- Java EE 7 ã§äžŠååŠçãã±ã¿éãã«éããªã! 䜿ãããªãã®ãã€ã³ãã¯? ââ Java Day Tokyo 2013 ã¬ããŒã - builder by ZDNet Japan
- ä»ãŸã§ç¥ããªãã£ã 5 ã€ã®äºé : java.util.concurrent 第 2 å