Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ263
Page ↗
Q263ArchFollow-up to Q212ASIC interview problem

Make the allocator thread-safe

TechniquesAllocatorSemaphoreConcurrency
DifficultyMedium
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Protect allocator invariants when several SystemVerilog processes may allocate, deallocate, or inspect state concurrently.

Class declarationSystemVerilog
class LockedRangeAllocator;
  task alloc_exclusive(
    int unsigned size,
    output int unsigned addr,
    output bit success
  );
  task dealloc_exclusive(
    int unsigned addr,
    int unsigned size,
    output bit success
  );
  task fragmentation_metrics_exclusive(
    output longint unsigned total_free,
    output int unsigned largest_block,
    output real external_ratio
  );
  task compact_exclusive(
    ref int unsigned relocated_addr[int unsigned]
  );
endclass

Example input and output

Use this case to check your interpretation
Input
process A calls alloc_exclusive(16, addr, ok) while process B calls dealloc_exclusive(0x1000,16,ok)
Output
one complete operation runs before the other; observers see either whole pre-state or whole post-state
Explanation

A single lock spans every metadata update and is released on success and failure, preventing partially coalesced state from escaping.

02

Requirements (4)

  • Use one lock for every operation touching allocator state.
  • Release the lock on every control path.
  • Do not expose partially updated range or allocation metadata.
  • Document that the wrapper blocks while another process owns the lock.