mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
userland: move some multithreaded examples from cpp-cheat
Using them mostly to evaluate how well the emulators are handling user mode multithreading.
This commit is contained in:
29
userland/posix/count_to.c
Normal file
29
userland/posix/count_to.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Count up to a given number 1 second sleep between each increment.
|
||||
*
|
||||
* https://github.com/cirosantilli/linux-kernel-module-cheat#unistd-h
|
||||
*
|
||||
* We need a separate program for this from count.c because count.c
|
||||
* is also usable as an init process, where we can't control the CLI
|
||||
* arguments very well.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned long i, max;
|
||||
if (argc > 1) {
|
||||
max = strtoll(argv[1], NULL, 0);
|
||||
} else {
|
||||
max = 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < max) {
|
||||
printf("%lu\n", i);
|
||||
i++;
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user