A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/doxyhtml/test__mt_8cpp_source.html below:

NCBI C++ ToolKit: src/corelib/test_mt.cpp Source File

59 #define TESTAPP_LOG_POST(x) do { ++m_LogMsgCount; LOG_POST(x); } while (0) 61 #define TESTAPP_ASSERT(expr, msg) \ 64  cerr << "Assertion failed: ("

<< #expr << ") --- " << msg << endl; \

104  virtual void OnExit

(

void

);

108 #ifdef USE_NATIVE_THREADS 112  void

RunNative(

void

);

113  void

JoinNative(

void

**

result

);

133  "CTestThread::CTestThread() - failed to initialize thread "

<<

m_Idx

);

142  "CTestThread::~CTestThread() - invalid number of threads: "

<< num);

145  "CTestThread::~CTestThread() - failed to destroy thread "

<<

m_Idx

);

153  "CTestThread::OnExit() - error exiting thread "

<<

m_Idx

);

175 #ifdef USE_NATIVE_THREADS 180

thread_obj->

Main

();

185 #if defined(NCBI_POSIX_THREADS) 190  return

NativeWrapper(arg);

193 #elif defined(NCBI_WIN32_THREADS) 198  return

NativeWrapper(arg);

204 void

CTestThread::RunNative(

void

)

209 #if defined(NCBI_WIN32_THREADS) 213  DWORD

creation_flags = 0;

215  this

, creation_flags, &thread_id);

221

0,

FALSE

, DUPLICATE_SAME_ACCESS),

222  "CTestThread::RunNative() - failed to duplicate thread handle"

);

224  "CTestThread::RunNative() - failed to close thread handle"

);

225 #elif defined(NCBI_POSIX_THREADS) 228  "CTestThread::RunNative() - failed to init thread attributes"

);

230

NativeWrapperCaller,

this

) == 0,

231  "CTestThread::RunNative() - failed to create thread"

);

233  "CTestThread::RunNative() - failed to destroy thread attributes"

);

239  TESTAPP_ASSERT

(0,

"CTestThread::RunNative() - threads are not supported"

);

245 void

CTestThread::JoinNative(

void

**

result

)

248 #if defined(NCBI_WIN32_THREADS) 250  "CTestThread::JoinNative() - failed to join thread"

);

253

&& status !=

DWORD

(STILL_ACTIVE),

254  "CTestThread::JoinNative() - failed to get thread exit code"

);

256  "CTestThread::JoinNative() - failed to close thread handle"

);

258 #elif defined(NCBI_POSIX_THREADS) 260  "CTestThread::JoinNative() - failed to join thread"

);

284  for

(

int i

= first_idx;

i

< first_idx + spawn_max;

i

++) {

287 #ifdef USE_NATIVE_THREADS 288  thr

[

i

]->RunNative();

318  virtual void

*

Main

(

void

);

326  unsigned int

number_of_threads,

327  bool

has_sync_point);

376  unsigned int

number_of_threads,

378

: m_Number_of_threads(number_of_threads), m_Has_sync_point(has_sync_point),

379

m_Semaphore(0,number_of_threads), m_SyncCounter(0)

383 #ifdef USE_NATIVE_THREADS 406  bool

reached =

false

;

432  "CThreadGroup::ThreadWait() - invalid number of threads: "

<< num);

471

arg_desc->AddDefaultKey

472

(

"threads"

,

"NumThreads"

,

473  "Total number of threads to create and run"

,

475

arg_desc->SetConstraint

479

arg_desc->AddDefaultKey

480

(

"repeats"

,

"NumRepeats"

,

481  "In non-MT mode only(!) -- how many times to repeat the test. " 482  "If passed 0, then the value of argument `-threads' will be used."

,

484

arg_desc->SetConstraint

488

arg_desc->AddDefaultKey

489

(

"spawnby"

,

"SpawnBy"

,

490  "Threads spawning factor"

,

492

arg_desc->SetConstraint

495

arg_desc->AddOptionalKey(

"seed"

,

"Randomization"

,

496  "Randomization seed value"

,

499

arg_desc->SetUsageContext(

GetArguments

().GetProgramBasename(),

500  "MT-environment test"

);

514 #if !defined(NCBI_THREADS) 520 #if !defined(NCBI_THREADS) 522  if

(!args[

"repeats"

].AsInteger()) {

531  s_SpawnBy

= args[

"spawnby"

].AsInteger();

534  "CThreadedApp::Run() - failed to initialize application"

);

537

?

static_cast<unsigned int>

(

GetArgs

()[

"seed"

].AsInteger())

542  unsigned int

threshold =

NCBI_PARAM_TYPE

(TEST_MT, Cascading)::GetDefault();

543  if

(threshold > 100) {

544  ERR_FATAL

(

"Cascading threshold must be less than 100"

);

546  bool

cascading = (

static_cast<unsigned int>

(rand() % 100)) < threshold;

547 #if !defined(NCBI_THREADS) 556 #if defined(NCBI_THREADS) 581  "CThreadedApp::Run() - thread "

<<

i

<<

" has not started"

);

582 #ifdef USE_NATIVE_THREADS 584  thr

[

i

]->JoinNative(&join_result);

586  "CThreadedApp::Run() - thread "

<<

i

<<

" failed to pass result to Join()"

);

589  thr

[

i

]->Join(&join_result);

591  "CThreadedApp::Run() - thread "

<<

i

<<

" failed to pass result to Join()"

);

598  for

(

unsigned int t

= 0;

601  thr

[

i

]->Join(&join_result);

603  "CThreadedApp::Run() - thread "

<<

i

<<

" failed to pass result to Join()"

);

607  "CThreadedApp::Run() - ivalid number of started threads: "

<<

m_Reached

.

size

());

611  "CThreadedApp::Run() - error exiting application"

);

635  ERR_FATAL

(

"Thread groups with no threads are not allowed"

);

638  unsigned int

threshold =

640  if

(threshold > 100) {

641  ERR_FATAL

(

"IntragroupSyncPoint threshold must be less than 100"

);

644  for

(

unsigned int g

= 0;

g

<

count

; ++

g

) {

647

group.has_sync_point = ((

unsigned int

)(rand() % 100)) < threshold;

648

group.number_of_threads = 1;

654  for

(

unsigned int t

= 0;

t

< threads_left; ++

t

) {

671  for

(

unsigned int g

= 0;

g

<

count

; ++

g

) {

692  unsigned int

start_now =

count

;

702  unsigned int

dest = rand() % (

m_Max

+1);

710

os <<

"Delayed thread groups: "

<< (

count

- start_now)

711

<<

", starting order: "

<< start_now;

769  thr

[idx]->SyncPoint();

779  "because TestApp_GlobalSyncPoint() was called"

);

787  thr

[idx]->GlobalSyncPoint();

792  unsigned int

num_min,

unsigned int

num_max)

CInGroupThread(CThreadGroup &group, int id)

virtual void SyncPoint(void)

virtual void * Main(void)

Derived (user-created) class must provide a real thread function.

CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:

virtual void * Main(void)

Derived (user-created) class must provide a real thread function.

virtual void GlobalSyncPoint(void)

virtual void * Main(void)

Derived (user-created) class must provide a real thread function.

CTestThread(CSeqDBAtlas &atlas)

static void StartCascadingThreads(void)

virtual void SyncPoint(void)

virtual void OnExit(void)

Override this to execute finalization code.

unsigned int m_Number_of_threads

unsigned int m_SyncCounter

CThreadGroup(unsigned int number_of_threads, bool has_sync_point)

void ThreadComplete(void)

iterator_bool insert(const value_type &val)

const_iterator find(const key_type &key) const

const_iterator end() const

virtual const CArgs & GetArgs(void) const

Get parsed command line arguments.

virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)

Setup the command line argument descriptions.

const CNcbiArguments & GetArguments(void) const

Get the application's cached unprocessed command-line arguments.

@ eInteger

Convertible into an integer number (int or Int8)

void Set(TValue new_value) THROWS_NONE

Set atomic counter value.

TValue Add(int delta) THROWS_NONE

Atomically add value (=delta), and return new counter value.

TValue Get(void) const THROWS_NONE

Get atomic counter value.

#define ERR_FATAL(message)

Posting fatal error and abort.

const unsigned int k_NumThreadsMin

Minimum number of threads.

vector< SThreadGroup > m_ThreadGroups

const unsigned int k_NumThreadsMax

Maximum number of threads.

unsigned int x_InitializeDelayedStart(void)

CThreadedApp(void)

Constructor.

virtual bool TestApp_Exit(void)

Override this method to execute code after all threads terminate.

unsigned int m_LogMsgCount

const int k_SpawnByMax

Maximum number of spawn by threads.

void SetNumberOfDelayedStartSyncPoints(unsigned int num_min, unsigned int num_max)

Set allowed range of delayed-start sync points.

~CThreadedApp(void)

Destructor.

virtual bool Thread_Run(int idx)

Run the thread.

int Run(void)

Run the threads.

virtual bool Thread_Destroy(int idx)

Destroy the thread.

void Init(void)

Initialize the app.

unsigned int s_NumThreads

atomic< unsigned int > m_NextGroup

virtual bool Thread_Init(int idx)

Initialize the thread.

const int k_SpawnByMin

Minimum number of spawn by threads.

virtual bool Thread_Exit(int idx)

Exit the thread.

void TestApp_IntraGroupSyncPoint(void)

Wait until other threads in group reach the same sync point The call may be ignored by the applicatio...

void x_PrintThreadGroups(void)

virtual bool TestApp_Init(void)

Override this method to execute code before running threads.

void TestApp_GlobalSyncPoint(void)

Wait until ALL threads reach a call of TestApp_GlobalSyncPoint().

void x_InitializeThreadGroups(void)

vector< unsigned int > m_Delayed

void TestApp_DelayedStartSyncPoint(const string &name)

Start threads that belong to delayed group (this call may be ignored to provide more randomness).

void x_StartThreadGroup(unsigned int count)

virtual bool TestApp_Args(CArgDescriptions &args)

Override this method to add your custom arguments.

#define NCBI_PARAM_TYPE(section, name)

Generate typename for a parameter from its {section, name} attributes.

#define END_NCBI_SCOPE

End previously defined NCBI scope.

#define BEGIN_NCBI_SCOPE

Define ncbi namespace.

static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)

Convert size_t to string.

static string IntToString(int value, TNumToStringFlags flags=0, int base=10)

Convert int to string.

static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)

Convert UInt to string.

static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)

Convert string to unsigned int.

static unsigned int GetRandomSeed(void)

Return a seed to use with srand() function to randomize new sequence of pseudo-random integers return...

void * TWrapperArg

Define platform-dependent argument wrapper.

TThreadHandle m_Handle

platform-dependent thread handle

void Lock(void)

Acquire mutex for the current thread with no nesting checks.

pthread_t TThreadHandle

Define platform-dependent thread handle type.

void Wait(void)

Wait on semaphore.

static void InitializeMainThreadId(void)

Initialize main thread's TID.

static TWrapperRes Wrapper(TWrapperArg arg)

Function to use (internally) as the thread's startup function.

void * TWrapperRes

Define platform-dependent result wrapper.

void Post(unsigned int count=1)

Increment the semaphore by "count".

void Unlock(void)

Release mutex with no owner or nesting checks.

@ fRunAllowST

Allow threads to run in single thread builds.

#define HANDLE

An abstraction for a file handle.

unsigned int

A callback function used to compare two keys in a database.

#define FALSE

bool replacment for C indicating false.

void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)

NCBI tests specific functions.

Multi-threading – mutexes; rw-locks; semaphore.

TWrapperRes(* FSystemWrapper)(TWrapperArg)

Thread group description parameters.

static CMiniMutex s_GlobalLock

static string s_GroupsCount(void)

NCBI_PARAM_DEF(unsigned int, TEST_MT, Cascading, 25)

DEFINE_STATIC_FAST_MUTEX(s_GlobalLock)

static CThreadedApp * s_Application

CRef< CTestThread > thr[k_NumThreadsMax]

static CAtomicCounter s_SyncCounter

static atomic< unsigned int > s_NextIndex

NCBI_PARAM_DECL(unsigned int, TEST_MT, Cascading)

NCBI_PARAM_DEF_WITH_INIT(string, TEST_MT, GroupsCount, "", s_GroupsCount)

#define TESTAPP_LOG_POST(x)

static CSemaphore s_Semaphore(0, INT_MAX)

#define TESTAPP_ASSERT(expr, msg)

static CAtomicCounter s_NumberOfThreads

static CStaticTls< int > s_ThreadIdxTLS

static CRef< CThreadGroup > thr_group[k_NumThreadsMax]

Wrapper for testing modules in MT environment.

int g(Seg_Gsm *spe, Seq_Mtf *psm, Thd_Gsm *tdg)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4