java - notifyall() not the last statement -


assume have read/write monitor implementation in java.

several readers or 1 writer can access database @ 1 time (not both)

class rwmonitor{    private int readers = 0;    private boolean writing = false;     public synchronized void startread(){ ..}    public synchronized void endread(){        notifyall();       readers--;    }     public synchronized void startwrite(){ ..}    public synchronized void endwrite(){       notifyall();       writing = false;    } } 

now, matter if notifyall() not last statement in synchronized method?

assume:

1) endread() executes

2) notifyall() notifies waiting threads

3) reduces reader count.

when executes notifyall(), more costly since woken threads waiting lock on rwmonitor released? (assuming thread has lock on rwmonitor still @ readers--;)

it not matter if last statement.

to quote javadoc notifyall():

the awakened threads not able proceed until current thread relinquishes lock on object.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -