Protothreading, a high level question

Hello, Ive been reading about protothreading and have been thinking about trying it out. However, I cannot quite grasp the difference between "protothreads" and an interrupt.

For example, lets say I have this code (just as a quick example)

int waterLevelSensor = 0;
int targetLevel = 20;
void loop() 
{
  waterLevelSensor = getWaterLevel();
  func(waterLevelSensor);
}

int getWaterLevel()
{
  // read in some data 
     return int data;
}

void func(int waterLevelSensor) 
{
  while((waterLevelSensor != targetLevel) &&(!checkOverflow))
  {
    waterLevelSensor = getWaterLevel();
    waterFill++;
    if(timer=2000)
    {
      checkOverflow();
    }
  }
}

bool checkOverflow()
{
  if(overflowing)
  {
   return true;
  }
return false;
}

I decide to interrupt my loop in fun() to check if we are overflowing
So what is the difference between doing that and "protothreading"?
Could someone perhaps give me an example of how something like that would be protothreaded?

Thank you, Cheers!

Nothing you're doing here involves an interrupt or a protothread.

I decide to interrupt my loop in fun() to check if we are overflowing

That's not an interrupt. That's just a function call. A regular old every-day line of code.

An interrupt is when some outside event (like a pin changing states) causes your program to stop running and some other function to run before control is returned to your function. It could happen at ANY POINT in your code.

Protothreading just means interleaving the parts of your program so that they appear to work at the same time. See any of the extended blink without delay examples or lookup the inner working of any of the myriad bloated libraries designed to handle BWoD for you.

Okay thank you that makes sense! I looked at this https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
and it seems like it is barely "threading" in any sense. It is just a timer in the main loop turning an LED on and off

akarbarz34:
Okay thank you that makes sense! I looked at this https://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
and it seems like it is barely "threading" in any sense. It is just a timer in the main loop turning an LED on and off

Yes. It doesn't have to be a LED, you could time anything with it. What more do you want on a single processor? How do you think "threading" would work in that case? The only option you have is to let processes take turns because you can only execute one instruction at a time.

Doing several things at the same time with Arduino