diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-12 21:24:39 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-01-12 21:24:39 +0000 |
commit | d42f24f8bf331b45734ad351249fec1093da0db1 (patch) | |
tree | 83b5c3d3cc92db7136c7996efcf0ee84987ac0ec /fastos | |
parent | 6fb9da718607e30498e7cd1d146df89ddbfdb448 (diff) |
- Wait for zero inactive threads before trying to start the one that shall fail.
- Also ensure that the started threads do not stop until we have completed the test.
Diffstat (limited to 'fastos')
-rw-r--r-- | fastos/src/tests/threadtest.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/fastos/src/tests/threadtest.cpp b/fastos/src/tests/threadtest.cpp index 3adaee58273..7c792ca9033 100644 --- a/fastos/src/tests/threadtest.cpp +++ b/fastos/src/tests/threadtest.cpp @@ -23,34 +23,29 @@ class ThreadTest : public ThreadTestBase if (Progress(pool != nullptr, "Allocating ThreadPool")) { int i; - Job jobs[MAX_THREADS]; + Job jobs[MAX_THREADS+1]; - for (i=0; i<MAX_THREADS; i++) { - jobs[i].code = PRINT_MESSAGE_AND_WAIT3MSEC; + for (i=0; i<MAX_THREADS+1; i++) { + jobs[i].code = WAIT_FOR_BREAK_FLAG; jobs[i].message = static_cast<char *>(malloc(100)); sprintf(jobs[i].message, "Thread %d invocation", i+1); } for (i=0; i<MAX_THREADS+1; i++) { if (i==MAX_THREADS) { - bool rc = (nullptr == pool->NewThread(this, static_cast<void *>(&jobs[0]))); + while (pool->GetNumInactiveThreads() > 0); + jobs[MAX_THREADS].code = PRINT_MESSAGE_AND_WAIT3MSEC; + bool rc = (nullptr == pool->NewThread(this, static_cast<void *>(&jobs[MAX_THREADS]))); Progress(rc, "Creating too many threads should fail."); } else { - bool rc = (nullptr != pool->NewThread(this, static_cast<void *>(&jobs[i]))); - Progress(rc, "Creating Thread"); + jobs[i].ownThread = pool->NewThread(this, static_cast<void *>(&jobs[i])); + Progress(jobs[i].ownThread != nullptr, "Creating Thread"); } - }; - - WaitForThreadsToFinish(jobs, MAX_THREADS); - - Progress(true, "Verifying result codes..."); - for (i=0; i<MAX_THREADS; i++) { - Progress(jobs[i].result == - static_cast<int>(strlen(jobs[i].message)), - "Checking result code from thread (%d==%d)", - jobs[i].result, strlen(jobs[i].message)); } - + for (i=0; i<MAX_THREADS; i++) { + jobs[i].ownThread->SetBreakFlag(); + } + Progress(true, "Closing threadpool..."); pool->Close(); |