FX:GBPCAD   Bảng Anh/Đô la Canada
if( _cursec != "" )
{
StaticVarSet( _cursec, 0 );
_cursec = "";
}
}
function TimeConsumingWork()
{
// WARNING: the Percentile is CPU hungry as it involves lots of sorting,
the loop below may take > 1 second to complete
for( i = 0; i< 10; i++ ) Percentile( C, 100, 10 );
}
//_TRACE("Without CS Begin " + GetChartID() );
//TimeConsumingWork(); // some time consuming calculation
//_TRACE("Without CS End" + GetChartID() );
// Example usage (critical section)
if( _TryEnterCS( "mysemaphore" ) )
{
// you are inside critical section now
_TRACE("Begin CS " + GetChartID() );
TimeConsumingWork(); // some time consuming calculation
_TRACE("End CS " + GetChartID() );
_LeaveCS();
}
else
{
_TRACE("Unable to enter CS");
// EXAMPLE 1 : Simple semaphore (no waiting)
if( StaticVarCompareExchange( "semaphore", 1, 0 ) == 0 ) // obtain
semaphore
{
// protected section here
// Here you have exclusive access (no other threads that check for
semaphore will enter simultaneously)
/////////////////////////
StaticVarSet("semaphore", 0 ); // reset semaphore
}
else
{
_TRACE("Can not obtain semaphore");
}
///////////////
// EXAMPLE 2 HOW TO IMPLEMENT CRITICAL SECTION IN AFL
///////////////
function _TryEnterCS( secname )
{
global _cursec;
_cursec= "";
// try obtaining semaphore for 1000 ms
for( i = 0; i < 1000; i++ )
if( StaticVarCompareExchange( secname, 1, 0 ) == 0 )
{
_cursec = secname;
break;
}
else ThreadSleep( 1 ); //sleep one millisecond
return _cursec != "";
}
// call it ONLY when _TryEnterCS returned TRUE !
function _LeaveCS()
{
global _cursec;
Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.