mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-15 00:52:27 +00:00
Remove __threaded variable
This commit is contained in:
parent
01b09bc817
commit
cf1559c448
15 changed files with 51 additions and 71 deletions
|
@ -179,47 +179,15 @@ void MallocFree(void) {
|
|||
free(p);
|
||||
}
|
||||
|
||||
void eat(void *p) {
|
||||
}
|
||||
|
||||
void (*pEat)(void *) = eat;
|
||||
|
||||
BENCH(bulk_free, bench) {
|
||||
/* pEat(pthread_create); */
|
||||
EZBENCH2("free() bulk", BulkFreeBenchSetup(), FreeBulk());
|
||||
EZBENCH2("bulk_free()", BulkFreeBenchSetup(),
|
||||
bulk_free(bulk, ARRAYLEN(bulk)));
|
||||
EZBENCH2("free(malloc(16)) ST", donothing, MallocFree());
|
||||
__enable_threads();
|
||||
EZBENCH2("free(malloc(16)) MT", donothing, MallocFree());
|
||||
}
|
||||
|
||||
#define ITERATIONS 1000
|
||||
#define THREADS 10
|
||||
#define SIZE 1024
|
||||
|
||||
void *Worker(void *arg) {
|
||||
for (int i = 0; i < ITERATIONS; ++i) {
|
||||
char *p;
|
||||
ASSERT_NE(NULL, (p = malloc(lemur64() % SIZE)));
|
||||
ASSERT_NE(NULL, (p = realloc(p, max(lemur64() % SIZE, 1))));
|
||||
free(p);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
TEST(malloc, torture) {
|
||||
int i, n = THREADS;
|
||||
pthread_t *t = gc(malloc(sizeof(pthread_t) * n));
|
||||
if (!n)
|
||||
return;
|
||||
printf("\nmalloc torture test w/ %d threads and %d iterations\n", n,
|
||||
ITERATIONS);
|
||||
SPAWN(fork);
|
||||
struct timespec t1 = timespec_real();
|
||||
for (i = 0; i < n; ++i) {
|
||||
ASSERT_EQ(0, pthread_create(t + i, 0, Worker, 0));
|
||||
}
|
||||
for (i = 0; i < n; ++i) {
|
||||
ASSERT_EQ(0, pthread_join(t[i], 0));
|
||||
}
|
||||
struct timespec t2 = timespec_real();
|
||||
printf("consumed %g wall and %g cpu seconds\n",
|
||||
timespec_tomicros(timespec_sub(t2, t1)) * 1e-6,
|
||||
(double)clock() / CLOCKS_PER_SEC);
|
||||
EXITS(0);
|
||||
EZBENCH2("free(malloc(16))", donothing, MallocFree());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue