]>
Commit | Line | Data |
---|---|---|
a78e148b | 1 | #include <stdio.h> |
2 | #include <stdlib.h> | |
3 | #include <pthread.h> | |
4 | #include <string.h> | |
5 | #include <assert.h> | |
6 | ||
7 | #define JEMALLOC_MANGLE | |
8 | #include "jemalloc_test.h" | |
9 | ||
10 | #define NTHREADS 10 | |
11 | ||
12 | void * | |
13 | thread_start(void *arg) | |
14 | { | |
15 | unsigned main_arena_ind = *(unsigned *)arg; | |
16 | void *p; | |
17 | unsigned arena_ind; | |
18 | size_t size; | |
19 | int err; | |
20 | ||
21 | p = JEMALLOC_P(malloc)(1); | |
22 | if (p == NULL) { | |
23 | fprintf(stderr, "%s(): Error in malloc()\n", __func__); | |
24 | return (void *)1; | |
25 | } | |
26 | ||
27 | size = sizeof(arena_ind); | |
28 | if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, | |
29 | &main_arena_ind, sizeof(main_arena_ind)))) { | |
30 | fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, | |
31 | strerror(err)); | |
32 | return (void *)1; | |
33 | } | |
34 | ||
35 | size = sizeof(arena_ind); | |
36 | if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL, | |
37 | 0))) { | |
38 | fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, | |
39 | strerror(err)); | |
40 | return (void *)1; | |
41 | } | |
42 | assert(arena_ind == main_arena_ind); | |
43 | ||
44 | return (NULL); | |
45 | } | |
46 | ||
47 | int | |
48 | main(void) | |
49 | { | |
50 | int ret = 0; | |
51 | void *p; | |
52 | unsigned arena_ind; | |
53 | size_t size; | |
54 | int err; | |
55 | pthread_t threads[NTHREADS]; | |
56 | unsigned i; | |
57 | ||
58 | fprintf(stderr, "Test begin\n"); | |
59 | ||
60 | p = JEMALLOC_P(malloc)(1); | |
61 | if (p == NULL) { | |
62 | fprintf(stderr, "%s(): Error in malloc()\n", __func__); | |
63 | ret = 1; | |
64 | goto RETURN; | |
65 | } | |
66 | ||
67 | size = sizeof(arena_ind); | |
68 | if ((err = JEMALLOC_P(mallctl)("thread.arena", &arena_ind, &size, NULL, | |
69 | 0))) { | |
70 | fprintf(stderr, "%s(): Error in mallctl(): %s\n", __func__, | |
71 | strerror(err)); | |
72 | ret = 1; | |
73 | goto RETURN; | |
74 | } | |
75 | ||
76 | for (i = 0; i < NTHREADS; i++) { | |
77 | if (pthread_create(&threads[i], NULL, thread_start, | |
78 | (void *)&arena_ind) != 0) { | |
79 | fprintf(stderr, "%s(): Error in pthread_create()\n", | |
80 | __func__); | |
81 | ret = 1; | |
82 | goto RETURN; | |
83 | } | |
84 | } | |
85 | ||
86 | for (i = 0; i < NTHREADS; i++) | |
87 | pthread_join(threads[i], (void *)&ret); | |
88 | ||
89 | RETURN: | |
90 | fprintf(stderr, "Test end\n"); | |
91 | return (ret); | |
92 | } |