例子: var __global lock; // 注意加__global是为了能在多线程中可访问 function main() { console.log('main start'); lock = new Lock(); var t = new Thread(); t.start(func); lock.lock(); console.log('main enter lock'); sleep(5000); console.log('main leave lock'); lock.unlock(); console.log('main end'); } function func() { console.log('func start'); lock.lock(); console.log('func enter lock'); sleep(5000); console.log('func leave lock'); lock.unlock(); console.log('func end'); }
参数名 | 类型 | 必填 | 说明 |
---|
参数名 | 类型 | 必填 | 说明 |
---|
参数名 | 类型 | 必填 | 说明 |
---|