Texts:
Q. Write a semaphore to solve the readers-writers problem that works as follows: If readers and writers both are waiting, then it alternates between readers and writers. Otherwise, it processes them normally (i.e., readers concurrently and writers serially).
Q. A power-of-2 allocator uses a minimum block size of 16 bytes and a maximum block size of 32KB. It starts its operation with one free block each of sizes 512 bytes, 2 KB, 16 KB, and 32KB. Calculate the internal and external fragmentation if the allocator processes use:
a) First-fit allocator
b) Best-fit allocator
c) Worst-fit allocator