1# test _thread lock objects with multiple threads 2# 3# MIT license; Copyright (c) 2016 Damien P. George on behalf of Pycom Ltd 4 5try: 6 import utime as time 7except ImportError: 8 import time 9import _thread 10 11lock = _thread.allocate_lock() 12 13 14def thread_entry(): 15 lock.acquire() 16 print("have it") 17 lock.release() 18 19 20# spawn the threads 21for i in range(4): 22 _thread.start_new_thread(thread_entry, ()) 23 24# wait for threads to finish 25time.sleep(1) 26print("done") 27