2006-03-28 11:44:19

by Kohei KaiGai

[permalink] [raw]
Subject: Fix pacct bug in multithreading case.

#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <sys/time.h>

#define BUFFER_SIZE (128 * 1024 * 1024) /* 128MB */

void *mychild(void *buffer) {
struct timeval tv;
u_int64_t t1, t2;

gettimeofday(&tv, NULL);
t1 = tv.tv_sec * 1000000 + tv.tv_usec;
t2 = t1 + 6 * 1000000;
/* heavy CPU/Mem job */
srand(tv.tv_usec);
while(t1 < t2) {
memset(buffer, rand(), BUFFER_SIZE);
gettimeofday(&tv, NULL);
t1 = tv.tv_sec * 1000000 + tv.tv_usec;
}
return NULL;
}

int main(int argc, char *argv[]) {
pthread_t pthread;
void *buffer = NULL;

buffer = malloc(BUFFER_SIZE);
if (!buffer)
return 1;

sleep(4);
pthread_create(&pthread, NULL, mychild, buffer);
sleep(1);
pthread_exit(0);
}


Attachments:
fixbug_pacct_incorrect_records.patch (1.74 kB)
bugacct.c (743.00 B)
Download all attachments