1

This question was tossed as a starting point in a technical interview at a semi-conductor company. I guess there are no right ans - the purpose of this open ended question is to gauge the engineer's depth and comfort level. Question:- design an API which monitors an address and returns when the address contains a specific value:-

void reach_target_value(volatile int* addr, int value);

My naive solution was something like this:-

void reach_target_value(volatile int* addr, int value)
{
  while(*addr != value)
  {
    //Do nothing - spin in a tight loop
  }
}

Now obviously in a multi processing/ multi threaded environment, it might miss to return if the address happens to reach the target value when the executing process/thread is context switched. Leaving this case how to enhance the code to ensure it works well in a multi-threaded environment where multiple threads would be monitoring the same address with different target values? Thanks for reading - would appreciate your suggestions - code - pointers!

1 Answer 1

7

Critical importance here is context of interview for a semi conductor company without knowing the role description, therefore this is impossibly broad.

Jumping into code with the information provided in the question is hopefully not what the interviewer was looking for.

You need to find out some fundamental requirements.... Is the address able to be monitored by hardware with alarms, generate interrupts on change, or does it need polling? Does the chip being used have functionality that could be utilized (e.g. generate an interrupt on modify address)

Is power use important (being a semi-conductor company they may be thinking monitoring an real time clock chip running off a button cell battery for years)

If polling, is the address change caused by asynchronous events or is a change cause by something in the programs control. How critical is it the system detects the value being looked? What frequency does the address need to be checked to ensure no possible instance of the value is missed. Does reading the address change its value? Is a change in value locked until read, or overwritten when a new value when it arrives.

Is this the only thing that needs to be performed while the address is being monitored

At the other end, the consumer of the API will need to be defined. Are they expected to 'baby sit' the API, or are they expecting a set and forget. Does the API run under an OS - if so is it an RTOS, or something more like Linux or something really basic relying on cooperative scheduling.

Given the interview was at a semi-conductor company, I would asking if hardware support for monitoring the address, if not available, could be added.

The answers to these will determine the API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.