Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS3214 Project 2 - A Fork-Join Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maxb24
CS3214 Project 2 - A Fork-Join Framework
Commits
932c2cb3
Commit
932c2cb3
authored
8 years ago
by
CS3214 Class Account
Browse files
Options
Downloads
Patches
Plain Diff
added threadpool_test5
parent
10bab1d1
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/Makefile
+4
-2
4 additions, 2 deletions
tests/Makefile
tests/threadpool_test5.c
+119
-0
119 additions, 0 deletions
tests/threadpool_test5.c
with
123 additions
and
2 deletions
tests/Makefile
+
4
−
2
View file @
932c2cb3
...
...
@@ -11,7 +11,7 @@
# for benchmarking
CFLAGS
=
-Wall
-O3
-Werror
-Wmissing-prototypes
-fopenmp
-std
=
gnu11
# for debugging
#CFLAGS=-Wall -O0 -g -Werror -Wmissing-prototypes
#CFLAGS=-Wall -O0 -g -Werror -Wmissing-prototypes
-std=gnu11
#CXXFLAGS=-Wall -O3 -Werror -fopenmp
CXXFLAGS
=
-Wall
-g
-Werror
-fopenmp
...
...
@@ -21,10 +21,12 @@ LDLIBS=-lpthread -lrt
OBJ
=
threadpool.o list.o threadpool_lib.o
ALL
=
quicksort psum_test fib_test mergesort nqueens
\
threadpool_test threadpool_test2 threadpool_test3 threadpool_test4
threadpool_test threadpool_test2 threadpool_test3 threadpool_test4
threadpool_test5
all
:
$(ALL)
threadpool_test5
:
threadpool_test5.o $(OBJ)
threadpool_test4
:
threadpool_test4.o $(OBJ)
threadpool_test3
:
threadpool_test3.o $(OBJ)
...
...
This diff is collapsed.
Click to expand it.
tests/threadpool_test5.c
0 → 100644
+
119
−
0
View file @
932c2cb3
/*
* Fork/Join Framework
*
* Test that the pool keeps processing tasks even in the absence of a call to
* future_get by external threads. (Filters out implementations that do not have
* a correct worker implementation that keeps checking the global queue.)
*
* Written by G. Back for CS3214 Spring 2016.
*/
#include
<assert.h>
#include
<pthread.h>
#include
<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<stdbool.h>
#include
<stdint.h>
#include
<unistd.h>
#include
<sys/time.h>
#include
<sys/resource.h>
#include
<time.h>
#include
"threadpool.h"
#include
"threadpool_lib.h"
#define DEFAULT_THREADS 2
#define DEFAULT_TASKS 40
struct
time_range
{
uintptr_t
taskno
;
struct
timeval
start
;
struct
timeval
end
;
};
static
int
count
;
static
void
*
test_task
(
struct
thread_pool
*
pool
,
struct
time_range
*
data
)
{
__sync_fetch_and_add
(
&
count
,
1
);
return
(
void
*
)
data
->
taskno
;
}
static
int
run_test
(
int
nthreads
,
int
ntasks
)
{
struct
benchmark_data
*
bdata
=
start_benchmark
();
struct
thread_pool
*
threadpool
=
thread_pool_new
(
nthreads
);
struct
time_range
start_end
[
ntasks
];
struct
future
*
futures
[
ntasks
];
printf
(
"starting %d tasks...
\n
"
,
ntasks
);
count
=
0
;
for
(
int
i
=
0
;
i
<
ntasks
;
i
++
)
{
start_end
[
i
].
taskno
=
i
;
futures
[
i
]
=
thread_pool_submit
(
threadpool
,
(
fork_join_task_t
)
test_task
,
start_end
+
i
);
}
struct
timespec
sleep_time
=
{
.
tv_sec
=
0
,
.
tv_nsec
=
200
*
1000
*
1000
// 200 ms should be plenty of time for those tasks to be
// processed.
};
nanosleep
(
&
sleep_time
,
NULL
);
if
(
count
!=
ntasks
)
{
fprintf
(
stderr
,
"Your pool did not make progress in the absence of calls to future_get
\n
"
);
abort
();
}
for
(
int
i
=
0
;
i
<
ntasks
;
i
++
)
{
uintptr_t
r
=
(
uintptr_t
)
future_get
(
futures
[
i
]);
// consistency check
if
(
r
!=
i
)
{
fprintf
(
stderr
,
"Wrong result, expected %d, got %lu
\n
"
,
i
,
r
);
abort
();
}
future_free
(
futures
[
i
]);
}
thread_pool_shutdown_and_destroy
(
threadpool
);
stop_benchmark
(
bdata
);
report_benchmark_results
(
bdata
);
printf
(
"Test successful.
\n
"
);
free
(
bdata
);
return
0
;
}
/**********************************************************************************/
static
void
usage
(
char
*
av0
,
int
exvalue
)
{
fprintf
(
stderr
,
"Usage: %s [-n <n>] [-t <t>]
\n
"
" -n number of threads in pool, default %d
\n
"
" -t number of tasks, default %d
\n
"
,
av0
,
DEFAULT_THREADS
,
DEFAULT_TASKS
);
exit
(
exvalue
);
}
int
main
(
int
ac
,
char
*
av
[])
{
int
c
,
nthreads
=
DEFAULT_THREADS
,
ntasks
=
DEFAULT_TASKS
;
while
((
c
=
getopt
(
ac
,
av
,
"hn:t:"
))
!=
EOF
)
{
switch
(
c
)
{
case
'n'
:
nthreads
=
atoi
(
optarg
);
assert
(
nthreads
>
1
||
!!!
"Cannot test for concurrency with only 1 thread"
);
break
;
case
't'
:
ntasks
=
atoi
(
optarg
);
break
;
case
'h'
:
usage
(
av
[
0
],
EXIT_SUCCESS
);
}
}
return
run_test
(
nthreads
,
ntasks
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment