Added common include for simple C programs, and threads-intro code

This commit is contained in:
Remzi Arpaci-Dusseau
2018-09-10 10:34:11 -05:00
parent f83b83e680
commit a72eedc5b6
5 changed files with 136 additions and 0 deletions

21
include/common.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef __common_h__
#define __common_h__
#include <sys/time.h>
#include <sys/stat.h>
#include <assert.h>
double GetTime() {
struct timeval t;
int rc = gettimeofday(&t, NULL);
assert(rc == 0);
return (double) t.tv_sec + (double) t.tv_usec/1e6;
}
void Spin(int howlong) {
double t = GetTime();
while ((GetTime() - t) < (double) howlong)
; // do nothing in loop
}
#endif // __common_h__