This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extended Faneuil Hall Problem | |
judge = 0 | |
entered = 0 | |
left = 0 | |
checked = 0 | |
nojudge = Sem(1) | |
allsignedin = Sem(0) | |
confirmed = Sem(0) | |
alldone = Sem(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Faneuil Hall Problem | |
entered = 0 | |
nojudge = Sem(1) | |
confirmed = Sem(0) | |
checkedin = Sem(0) | |
Immigrant thread | |
nojudge.wait() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Senate Bus Problem | |
riders = 0 | |
mutex = Sem(1) | |
multiplex = Sem(50) | |
bus = Sem(0) | |
allAboard = Sem(0) | |
Bus thread |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Room Party Problem | |
students = 0 | |
dean = 'not here' | |
mutex = Sem(1) | |
turn = Sem(1) | |
wait = Sem(0) | |
Dean thread | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Werror -std=c11 -Wall -Wextra -Wno-error=unused-parameter -Wno-error=unused-function -Wno-error=unused-variable -Wconversion -Wno-error=sign-conversion -fsanitize=address,undefined -g3 -o unaligned_access unaligned_access.c | |
// Expected runtime error: | |
// ~/projects/tmp $ ./unaligned_access | |
// unaligned_access.c:72:20: runtime error: member access within misaligned address 0x6210000010c7 for type 'struct io_data', which requires 8 byte alignment | |
#include <stdlib.h> | |
#include <sys/uio.h> | |
#include <stddef.h> | |
#include <stdint.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -Werror -Wall -Wextra -D_FILE_OFFSET_BITS=64 -O2 -o read_file read_file.c | |
#include <stdlib.h> | |
#include <stddef.h> | |
#include <sys/stat.h> | |
#include <stdint.h> | |
int main(void) | |
{ | |
off_t file_sz = 1LL << 32; | |
ptrdiff_t block_sz = 1 << 27; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section ".text" | |
// On-board LED | |
#ifdef __ARM_ARCH_7A__ | |
// Pin 47 | |
mov r1, #0x8000 | |
#else | |
// Pin 16 | |
mov r1, #0x10000 | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Find 64-bit hash collisions using a rainbow table | |
// | |
// Prints string collision pairs, one per line, until running out of | |
// memory or manually stopped. | |
// | |
// Porting: Implement fullwrite() and an entry point that calls worker() | |
// on one thread per CPU core. | |
// | |
// This is free and unencumbered software released into the public domain. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Refer to: https://nullprogram.com/blog/2015/05/15/ | |
// https://nullprogram.com/blog/2023/02/15/ | |
// https://nullprogram.com/blog/2023/03/23/ | |
// gcc -Werror -std=gnu99 -Wall -Wextra -Wno-error=unused-parameter -Wno-error=unused-function -Wno-error=unused-variable -Wconversion -Wno-error=sign-conversion -fno-builtin -nostdlib -march=armv7-a -O2 -o clone_arm clone_arm.c | |
#include <unistd.h> | |
#include <stddef.h> | |
#include <syscall.h> | |
#define assert(c) while (!(c)) __builtin_trap() | |
#define sizeof(x) (ptrdiff_t) sizeof(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Refer to: https://nullprogram.com/blog/2023/03/23/ | |
// gcc -Werror -std=gnu99 -Wall -Wextra -Wno-error=unused-parameter -Wno-error=unused-function -Wno-error=unused-variable -Wconversion -Wno-error=sign-conversion -g3 -o syscall_arm syscall_arm.c | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#include <syscall.h> | |
#define countof(a) (sizeof(a) / sizeof(*(a))) | |
#define lengthof(s) (countof(s) - 1) | |
#define SYSCALL1(n, a) \ |
NewerOlder