Discussion:
[問題] 請問synchronized的種類
(时间太久无法回复)
Theseus
2006-12-15 20:41:05 UTC
Permalink
請問Java中的synchronized 是屬於

1. busy waiting semphore

2. suspend and wakup semphore

還是都不是

希望板上有人可以為我解答 謝謝

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.117.120.213
!H45
2006-12-15 21:06:55 UTC
Permalink
※ 引述《Theseus914 (Theseus)》之銘言:
: 請問Java中的synchronized 是屬於
: 1. busy waiting semphore
: 2. suspend and wakup semphore
: 還是都不是
: 希望板上有人可以為我解答 謝謝

suspend and wakeup semphore

* First, it is not possible for two invocations of synchronized methods
on the same object to interleave. When one thread is executing a synchronized
method for an object, all other threads that invoke synchronized methods for
the same object block (suspend execution) until the first thread is done with
the object.
* Second, when a synchronized method exits, it automatically establishes
a happens-before relationship with any subsequent invocation of a
synchronized method for the same object. This guarantees that changes to the
state of the object are visible to all threads.

Ref:
http://java.sun.com/docs/books/tutorial/essential/concurrency/syncmeth.html

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.205.85

继续阅读narkive:
Loading...