educative.io

Printer example looks contradicting to the explaining

According to the explaining, the necessary tasks of printer should be done before releasing the lock. Therefore I think the following code should be used:

def printer_thread():
    global prime_holder
    global found_prime

    while not exit_prog:

        # wait for a prime number to become
        # available for printing
        cond_var.acquire()
        while not found_prime and not exit_prog:
            cond_var.wait()
        if not exit_prog
            print(prime_holder)
        prime_holder = None
        found_prime = False
        cond_var.notify()
        cond_var.release()

Type your question above this line.

Course: https://www.educative.io/collection/5307417243942912/5668546535227392
Lesson: https://www.educative.io/collection/page/5307417243942912/5668546535227392/5353068822528000