-
Notifications
You must be signed in to change notification settings - Fork 8
/
testcase-cpuquota.txt
34 lines (33 loc) · 1 KB
/
testcase-cpuquota.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Control.Concurrent
import Control.Monad
import System.Process
main :: IO ()
main = do
writeFile "a.c"
"#include <stdio.h>\n\
\#include <pthread.h>\n\
\#include <assert.h>\n\
\const int N = 3;\n\
\void* zooi(void *n) {\n\
\ int k = *(int*)n;\n\
\ for (int i = 0; i < 40000; i++)\n\
\ for (int j = 0; j < 40000; j++)\n\
\ k = k * (i + j) + 3;\n\
\ printf(\"%d\\n\", k);\n\
\ return NULL;\n\
\}\n\
\int main(int argc, char **argv) {\n\
\ pthread_t ths[N];\n\
\ pthread_attr_t attr;\n\
\ assert(pthread_attr_init(&attr) == 0);\n\
\ for (int i = 0; i < N; i++) {\n\
\ assert(pthread_create(&ths[i], &attr, &zooi, &argc) == 0);\n\
\ }\n\
\ pthread_attr_destroy(&attr);\n\
\ for (int i = 0; i < N; i++) {\n\
\ assert(pthread_join(ths[i], NULL) == 0);\n\
\ }\n\
\}\n"
callProcess "gcc" ["-Wall", "-O2", "a.c", "-o", "a", "-pthread"]
putStrLn $ "Running ./a"
callProcess "bash" ["-c", "time ./a"]