* Fork/Join Framework Copyright By PowCoder代写 加微信 powcoder #include #include “threadpool.h” /* Data to be passed to callable. */ * A FJ task that adds 2 numbers. static int struct arg2 args = { struct future * sum = thread_pool_submit(threadpool, (fork_join_task_t) adder_task, &args); uintptr_t ssum = (uintptr_t) future_get(sum); stop_benchmark(bdata); // consistency check report_benchmark_results(bdata); /**********************************************************************************/ static void main(int ac, char *av[]) return run_test(nthreads); 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com
* Tests simple task execution.
* Written by G. Back for CS3214 Fall 2014.
#include
#include
#include
#include
#include
#include
#include
#include
#include “threadpool_lib.h”
#define DEFAULT_THREADS 1
struct arg2 {
uintptr_t a;
uintptr_t b;
static void *
adder_task(struct thread_pool *pool, struct arg2 * data)
return (void *)(data->a + data->b);
run_test(int nthreads)
struct benchmark_data * bdata = start_benchmark();
struct thread_pool * threadpool = thread_pool_new(nthreads);
future_free(sum);
thread_pool_shutdown_and_destroy(threadpool);
if (ssum != 42) {
fprintf(stderr, “Wrong result, expected 42, got %ld\n”, ssum);
printf(“Test successful.\n”);
free(bdata);
usage(char *av0, int exvalue)
fprintf(stderr, “Usage: %s [-n
” -n number of threads in pool, default %d\n”
, av0, DEFAULT_THREADS);
exit(exvalue);
int c, nthreads = DEFAULT_THREADS;
while ((c = getopt(ac, av, “hn:”)) != EOF) {
switch (c) {
nthreads = atoi(optarg);
usage(av[0], EXIT_SUCCESS);