示例#1
0
文件: nfibs.c 项目: NV/nile
int main(int argc, char **argv)
{
    while (--argc) {
	int arg= atoi(*++argv);
	printf("nfibs(%d) = %d\n", arg, fibs(arg));
    }
    return 0;
}
示例#2
0
static void task_cb(void *udata) {
    struct threadpool *t = (struct threadpool *)udata;

    for (;;) {
        if (ATOMIC_BOOL_COMPARE_AND_SWAP(&task_count, task_count, task_count + 1)) {
            break;
        }
    }

    size_t arg = task_count;
    arg = 30 + (random() % 10);

    size_t tc = task_count;

    size_t res = fibs(arg);

    printf("%zd -- fibs(%zd) => %zd", tc, arg, res);

    struct threadpool_info stats;
    Threadpool_Stats(t, &stats);
    dump_stats("", &stats);
}
示例#3
0
文件: nfibs.c 项目: NV/nile
int fibs(long n)
{
  return (n < 2) ? 1 : (fibs(n - 1) + fibs(n - 2) + 1);
}
static size_t fibs(size_t arg) {
    if (arg < 2) { return 1; }
    return fibs(arg - 1) + fibs(arg - 2);
}