MCPcopy Create free account
hub / github.com/Kitware/VTK / RunThreads

Function RunThreads

Parallel/Core/Testing/Cxx/TestThreadedCallbackQueue.cxx:21–55  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

19{
20//-----------------------------------------------------------------------------
21void RunThreads(int nthreadsBegin, int nthreadsEnd)
22{
23 vtkNew<vtkThreadedCallbackQueue> queue;
24 std::atomic_int count(0);
25 int N = 10000;
26
27 // Spamming controls
28 for (int i = 0; i < 6; ++i)
29 {
30 queue->SetNumberOfThreads(nthreadsBegin);
31 queue->SetNumberOfThreads(nthreadsEnd);
32 }
33
34 // We are testing if the queue can properly resize itself and doesn't have deadlocks
35 for (vtkIdType i = 0; i < N; ++i)
36 {
37 vtkSmartPointer<vtkIntArray> array = vtkSmartPointer<vtkIntArray>::New();
38 queue->Push(
39 [&count](const int& n, const double&&, char, vtkIntArray* a1, vtkIntArray* a2)
40 {
41 a1->SetName(vtk::to_string(n).c_str());
42 a2->SetName(vtk::to_string(n).c_str());
43 ++count;
44 },
45 i, 0, 'a', vtkNew<vtkIntArray>(), array);
46 }
47
48 // If the jobs are not run, this test will do an infinite loop
49 while (count != N)
50 ;
51
52 // Checking how the queue behaves when being destroyed.
53 queue->SetNumberOfThreads(nthreadsBegin);
54 queue->SetNumberOfThreads(nthreadsEnd);
55}
56
57//=============================================================================
58struct A

Callers 1

Calls 6

NewFunction · 0.50
to_stringFunction · 0.50
SetNumberOfThreadsMethod · 0.45
PushMethod · 0.45
SetNameMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected