This source file includes following definitions.
- mess_with_num_threads
- main
#include "HalideRuntime.h"
#include "HalideBuffer.h"
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include "variable_num_threads.h"
bool stop = false;
int max_threads = 1;
using namespace Halide::Runtime;
void mess_with_num_threads(void *) {
while (!stop) {
halide_set_num_threads((rand() % max_threads) + 1);
}
}
int main(int argc, char **argv) {
halide_set_num_threads(1);
halide_thread *t = halide_spawn_thread(&mess_with_num_threads, NULL);
Buffer<float> out(64, 64);
for (int i = 0; i < 1000; i++) {
max_threads = 1 + std::min(i, 1000-i) / 50;
int ret = variable_num_threads(out);
if (ret) {
printf("Non zero exit code: %d\n", ret);
return -1;
}
}
stop = true;
halide_join_thread(t);
printf("Success\n");
return 0;
}