see also
- http://tutorials.jenkov.com/java-concurrency/thread-pools.html
class AClass {
private int count =0;
public synchronized inc(){
count++;
}
public synchronized dec(){
count--;
}
}
import threading
class AClass(object):
def __init__(self):
self.__count = 0;
self.__lock = threading.RLock()
def inc(self):
with self.__lock:
self.__count += 1
def dec(self):
with self.__lock:
self.__count -= 1
class AClass {
private static int _count = 0;
public static synchronized inc(){
_count ++;
}
public static synchronized dec(){
_count --;
}
}
import threading
class AClass(object):
__count = 0
__lock = threading.RLock()
@classmethod
def inc(cls):
with cls.__lock:
cls.__count += 1
@classmethod
def dec(cls):
with cls.__lock:
cls.__count -= 1