import threading
import time

#mutex = threading.Lock()  # is equal to threading.Semaphore(1)
mutex = threading.Semaphore(1)  # is equal to threading.Semaphore(1)
#mutex = threading.Semaphore(2)  # is equal to threading.Semaphore(1)

def fA():
    mutex.acquire()
    while True:
        print("a")
        time.sleep(.5)
    mutex.release()


def fB():
    mutex.acquire()
    while True:
        print("b")
        time.sleep(.5)
    mutex.release()

t1 = threading.Thread(target=fA)
t2 = threading.Thread(target=fB)
t1.start()
t2.start()
