+#include <errno.h>
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
-#include <stdint.h>
-#include <inttypes.h>
-#include <unistd.h>
-#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <time.h>
-#include <pthread.h>
+#include <unistd.h>
struct thread_state {
pthread_t thread;
struct thread_state *ts = (struct thread_state *)arg;
char namebuf[64];
- sprintf(namebuf, "file-%d", ts->thread_num);
+ sprintf(namebuf, "file-%d", ts->thread_num + 1);
printf("Opening %s\n", namebuf);
int64_t start, end;
start = now_hires();
+
+ struct stat stat_buf;
+ stat(namebuf, &stat_buf);
+
+#if 0
FILE *f = fopen(namebuf, "rb");
if (f == NULL) {
perror("fopen");
char buf[4096];
fread(buf, 1, sizeof(buf), f);
+#endif
end = now_hires();
printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
- fclose(f);
+ // fclose(f);
return NULL;
}
int main(int argc, char *argv[])
{
- for (int i = 0; i < 8; i++) {
+ int threads = 8;
+
+ if (argc > 1)
+ threads = atoi(argv[1]);
+ if (threads > MAX_THREADS)
+ threads = MAX_THREADS;
+
+ printf("Testing with %d threads\n", threads);
+
+ for (int i = 0; i < threads; i++) {
launch_thread(i);
}
- for (int i = 0; i < 8; i++) {
+ for (int i = 0; i < threads; i++) {
wait_thread(i);
}