Q: Threading with priority queue I wanted to test threads in python, so I tried to create 3 threads that run at the same time but each one prints a different letter from A - C.
It was easy so I added that the letters would be printed from first to last and I'm getting confused from here.
How can I make 3 threads that run talk to each other and to know when to print and when to not print?
the output should be:
A B C A B C A B C A B C

my code:
import threading
import time
import queue

val = 0


def increment(letter):
    global val
    for x in range(100):
        val += 1
        lock.acquire()
        time.sleep(0.5)
        print(val, letter, ' ')
        lock.release()


lock = threading.Lock()
thread1 = threading.Thread(target=increment, args=('A',))
thread2 = threading.Thread(target=increment, args=('B',))
thread3 = threading.Thread(target=increment, args=('C',))
thread1.start()
thread2.start()
thread3.start()

