DEV Community

Oluwanifemi Latunde
Oluwanifemi Latunde

Posted on

Print in Order

It's day four already💃🏽. Today's challenge was on printing in order. Basically, the challenge was about synchronisation. It involved designing a mechanism and modifying the program to ensure that second() is executed after first(), and third() is executed after second().

I used the locking tool of the threading module in python which was a new concept I just learnt.

Locks are a synchronisation tool included in the Python threading module. Locks exist in two states:

  • Locked
  • Unlocked

With the use of the acquire() method, a lock can be locked. All additional attempts to acquire the lock are prohibited once a thread has already gained it until it is released. The release() method can be used to release the lock.

The syntax was to release the first thread and lock the other two. Once the first thread has been executed it is locked and the sequence repeats till all the threads have been executed.

It was a fun challenge to execute overall.

Thank You❤️

Top comments (0)

50 CLI Tools You Can't Live Without

>> Check out this classic DEV post <<