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 condition variable object, which is used to implement synchronization and communication between threads in a multi-threaded concurrent environment. Through Condition(), a thread can enter a waiting state when specific conditions are not met, until another thread signals that the conditions have been met.

Condition()

Examples

Two concurrent threads accessing shared resources.

javascript
function consumer(productionQuantity, dict, condition) { for (var i = 0; i < productionQuantity; i++) { condition.acquire() while (dict.get("array").length == 0) { condition.wait() } var arr = dict.get("array") var count = arr.shift() dict.set("array", arr) Log("consumer:", count, ", array:", arr) condition.release() Sleep(1000) } } function producer(productionQuantity, dict, condition) { for (var i = 0; i < productionQuantity; i++) { condition.acquire() var arr = dict.get("array") arr.push(i) dict.set("array", arr) Log("producer:", i, ", array:", arr) condition.notify() condition.release() Sleep(1000) } } function main() { var dict = threading.Dict() dict.set("array", []) var condition = threading.Condition() var productionQuantity = 10 var producerThread = threading.Thread(producer, productionQuantity, dict, condition) var consumerThread = threading.Thread(consumer, productionQuantity, dict, condition) consumerThread.join() producerThread.join() }

Returns

TypeDescription

ThreadCondition object

ThreadCondition object.

See Also

Remarks

The backtesting system does not currently support this feature, only the interface definition is provided.