Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.submit
Subscription
threading
threading.Thread
threading.getThread
threading.mainThread
threading.currentThread
threading.Lock
threading.Condition
threading.Event
threading.Dict
threading.Serve
threading.pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Creates a thread lock object.

Lock()

Examples

Two concurrent threads accessing shared resources.

javascript
function consumer(productionQuantity, dict, lock) { for (var i = 0; i < productionQuantity; i++) { lock.acquire() var count = dict.get("count") Log("consumer:", count) Sleep(1000) lock.release() } } function producer(productionQuantity, dict, lock) { for (var i = 0; i < productionQuantity; i++) { lock.acquire() dict.set("count", i) Log("producer:", i) Sleep(1000) lock.release() } } function main() { var dict = threading.Dict() dict.set("count", -1) var lock = threading.Lock() var productionQuantity = 10 var producerThread = threading.Thread(producer, productionQuantity, dict, lock) var consumerThread = threading.Thread(consumer, productionQuantity, dict, lock) consumerThread.join() producerThread.join() }

Returns

TypeDescription

ThreadLock object

Thread lock object.

See Also

Remarks

Supports backtesting system and live trading environment.