CS计算机代考程序代写 #include

#include
#include “uthread.h”
#include “spinlock.h”

#define LIMIT 100000L
long counter = 0;

spinlock_t lock;

void *counting_thread(void *arg) {

char *name = arg;
int i;

for (i = 0; i < LIMIT; i++) { counter++; } return 0; /* Success */ } int main(int argc, char **argv) { uthread_t t1, t2; uthread_init(2); spinlock_create(&lock); t1 = uthread_create(counting_thread, "ping"); t2 = uthread_create(counting_thread, "pong"); uthread_join(t1, NULL); uthread_join(t2, NULL); printf("Final counter = %ld, should be %ld\n", counter, LIMIT * 2); return 0; }