Skip to content

Commit 8416bab

Browse files
Alexey Frunzebjacob
Alexey Frunze
authored andcommitted
Fix #136 (test_blocking_counter)
1 parent 7d6d123 commit 8416bab

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Intel Corporation
1111
ARM Ltd.
1212
Silk Labs Inc.
1313
MIPS Tech LLC
14+
Wave Computing Inc.

CONTRIBUTORS

+2
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ Andreas Gal <[email protected]>
3535
MIPS Tech LLC:
3636
Alexey Frunze <[email protected]>
3737

38+
Wave Computing Inc.:
39+
Alexey Frunze <[email protected]>

test/test_blocking_counter.cc

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
#include <atomic> // NOLINT
1616
#include <vector>
17+
#include <iostream>
18+
#include <cstdlib>
1719

1820
#include "../internal/multi_thread_gemm.h"
1921
#include "../profiling/pthread_everywhere.h"
@@ -28,7 +30,28 @@ class Thread {
2830
number_of_times_to_decrement_(number_of_times_to_decrement),
2931
made_the_last_decrement_(false),
3032
finished_(false) {
33+
#if defined GEMMLOWP_USE_PTHREAD
34+
// Limit the stack size so as not to deplete memory when creating
35+
// many threads.
36+
pthread_attr_t attr;
37+
int err = pthread_attr_init(&attr);
38+
if (!err) {
39+
size_t stack_size;
40+
err = pthread_attr_getstacksize(&attr, &stack_size);
41+
if (!err && stack_size > max_stack_size_) {
42+
err = pthread_attr_setstacksize(&attr, max_stack_size_);
43+
}
44+
if (!err) {
45+
err = pthread_create(&thread_, &attr, ThreadFunc, this);
46+
}
47+
}
48+
if (err) {
49+
std::cerr << "Failed to create a thread.\n";
50+
std::abort();
51+
}
52+
#else
3153
pthread_create(&thread_, nullptr, ThreadFunc, this);
54+
#endif
3255
}
3356

3457
~Thread() { Join(); }
@@ -55,6 +78,7 @@ class Thread {
5578
return nullptr;
5679
}
5780

81+
static const size_t max_stack_size_ = 256 * 1024;
5882
BlockingCounter* const blocking_counter_;
5983
const int number_of_times_to_decrement_;
6084
pthread_t thread_;

0 commit comments

Comments
 (0)