To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit dc3e2227 authored by Horea Christian's avatar Horea Christian
Browse files

Merge branch 'master' of gitlab.ethz.ch:thealternative/courses

parents 2d6bf4ca 7c0f2f2a
int
main(int argc, char **argv) {
int arr[10];
arr[11] = 1;
return 0;
}
#include<pthread.h>
pthread_mutex_t lock1 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t lock2 = PTHREAD_MUTEX_INITIALIZER;
void *
thread1(void *arg __attribute__((unused))) {
pthread_mutex_lock(&lock1);
pthread_mutex_lock(&lock2); //Lock-Order-Inversion between here...
pthread_mutex_unlock(&lock2);
pthread_mutex_unlock(&lock1);
return NULL;
}
void *
thread2(void *arg __attribute__((unused))) {
pthread_mutex_lock(&lock2);
pthread_mutex_lock(&lock1); // ... and here!
pthread_mutex_unlock(&lock1);
pthread_mutex_unlock(&lock2);
return NULL;
}
int
main(int argc, char **argv) {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread1, NULL);
pthread_create(&t2, NULL, thread2, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
#include<stdlib.h>
int
main(int argc, char **argv) {
int *p;
p = malloc(sizeof(int));
return 0;
}
#include<pthread.h>
volatile int inc;
void *
thread(void *arg __attribute__((unused))) {
for (int i = 0; i < 65536; i++)
inc++;
return NULL;
}
int
main(int argc, char **argv) {
pthread_t t1, t2;
pthread_create(&t1, NULL, thread, NULL);
pthread_create(&t2, NULL, thread, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
#include<stdlib.h>
int
main(int argc, char **argv) {
int *ip;
ip = malloc(sizeof(int));
free(ip);
*ip = 3;
return 0;
}
int
main(int argc, char **argv) {
int i = 32;
int j = 0xCAFFEE;
j = j << i;
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
int i;
if (i)
printf("Hui\n");
else
printf("Pfui\n");
return 0;
}
#include<stdio.h>
#include<stdbool.h>
#include<tgmath.h>
bool
is_prime(int number) {
int max = ((int) sqrt((double) number)) + 1;
for (int i = 2; i < max; i++)
if (!(number % i))
return false;
return true;
}
int
main(int argc, char** argv) {
int number;
scanf("%d", &number);
if (is_prime(number))
printf("%d: prime\n", number);
else
printf("%d: not prime\n", number);
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
FILE *f = fopen("/tmp/test", "w+");
fprintf(f, "Hello\n");
fclose(f);
printf("Done!\n");
return 0;
}
#include<stdio.h>
int
main(int argc, char **argv) {
printf("Hello World!");
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment