Rev 2787 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2787 | Rev 4692 | ||
---|---|---|---|
Line 25... | Line 25... | ||
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ |
28 | */ |
29 | 29 | ||
30 | #define THREADS 5 |
30 | #define THREADS 20 |
- | 31 | #define DELAY 10 |
|
31 | 32 | ||
32 | #include <atomic.h> |
33 | #include <atomic.h> |
33 | #include <thread.h> |
34 | #include <thread.h> |
34 | #include <stdio.h> |
35 | #include <stdio.h> |
35 | #include <unistd.h> |
36 | #include <unistd.h> |
36 | #include "../tester.h" |
37 | #include "../tester.h" |
37 | 38 | ||
38 | static atomic_t finish; |
39 | static atomic_t finish; |
39 | static atomic_t threads_finished; |
40 | static atomic_t threads_finished; |
40 | static bool sh_quiet; |
- | |
41 | 41 | ||
42 | static void threadtest(void *data) |
42 | static void threadtest(void *data) |
43 | { |
43 | { |
44 | thread_detach(thread_get_id()); |
44 | thread_detach(thread_get_id()); |
45 | 45 | ||
46 | while (atomic_get(&finish)) { |
46 | while (atomic_get(&finish)) |
47 | if (!sh_quiet) |
- | |
48 | printf("%llu ", thread_get_id()); |
- | |
49 | usleep(100000); |
47 | usleep(100000); |
50 | } |
48 | |
51 | atomic_inc(&threads_finished); |
49 | atomic_inc(&threads_finished); |
52 | } |
50 | } |
53 | 51 | ||
54 | char * test_thread1(bool quiet) |
52 | char *test_thread1(void) |
55 | { |
53 | { |
56 | unsigned int i, total = 0; |
54 | unsigned int i; |
57 | sh_quiet = quiet; |
55 | int total = 0; |
58 | 56 | ||
59 | atomic_set(&finish, 1); |
57 | atomic_set(&finish, 1); |
60 | atomic_set(&threads_finished, 0); |
58 | atomic_set(&threads_finished, 0); |
61 | 59 | ||
- | 60 | TPRINTF("Creating threads"); |
|
62 | for (i = 0; i < THREADS; i++) { |
61 | for (i = 0; i < THREADS; i++) { |
63 | if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) { |
62 | if (thread_create(threadtest, NULL, "threadtest", NULL) < 0) { |
64 | if (!quiet) |
- | |
65 | printf("Could not create thread %d\n", i); |
63 | TPRINTF("\nCould not create thread %u\n", i); |
66 | break; |
64 | break; |
67 | } |
65 | } |
- | 66 | TPRINTF("."); |
|
68 | total++; |
67 | total++; |
69 | } |
68 | } |
70 | 69 | ||
71 | if (!quiet) |
- | |
72 | printf("Running threads for 10 seconds...\n"); |
70 | TPRINTF("\nRunning threads for %u seconds...", DELAY); |
73 | sleep(10); |
71 | sleep(DELAY); |
- | 72 | TPRINTF("\n"); |
|
74 | 73 | ||
75 | atomic_set(&finish, 0); |
74 | atomic_set(&finish, 0); |
76 | while (atomic_get(&threads_finished) < total) { |
75 | while (atomic_get(&threads_finished) < total) { |
77 | if (!quiet) |
- | |
78 | printf("Threads left: %d\n", total - atomic_get(&threads_finished)); |
76 | TPRINTF("Threads left: %u\n", total - atomic_get(&threads_finished)); |
79 | sleep(1); |
77 | sleep(1); |
80 | } |
78 | } |
81 | 79 | ||
82 | return NULL; |
80 | return NULL; |
83 | } |
81 | } |