Re: Is this a valid construct?

From: Bill Wendling (wendling@ganymede.isdn.uiuc.edu)
Date: Mon Oct 16 2000 - 17:37:29 EST


Also sprach Matthew Dharm:
} Does the following pseudocode do what I think it does?
}
} Assume the semaphore is properly initialized to locked.
}
} int flagvar = 0;
} struct semaphore blocking_sem;
}
} void function_called_from_kernel_thread(void)
} {
} chew_on_hardware();
} flagvar = 1;
} down(blocking_sem);
}
} if (flagvar)
} printk("something went wrong")
} else
} printk("everything okay")
} }
}
} void function_called_from_interrupt_context()
} {
} flagvar = 0;
} up(blocking_sem);
} }
}
} void function_to_call_from_timeout()
} {
} up(blocking_sem);
} }
}
} The idea is this -- I chew on the hardware, then sleep on the semaphore. I
} then either get woken up by an IRQ (which may never come), or the timeout.
} I then try to use the flagvar to determine which of the two happened.
}
} This _looks_ valid to me... but I'm seeing occurances where I get the IRQ
} (yes, I'm sure of it) but flagvar == 1, which confuses me.
}
Are you sure there isn't a race on the flagvar variable? Like, the
interrupt happens, it gets set to 0, then before we can ``up'' the
semaphore, it's set to 1 in the function_called_from_kernel_thread()?

-- 
|| Bill Wendling			wendling@ganymede.isdn.uiuc.edu


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Oct 23 2000 - 21:00:10 EST