Callouts and Race Conditions

Because callout functions execute asynchronously, it’s possible for a callout function to be called while another thread attempts to stop or reschedule it; thus creating a race condition. Fortunately, there are two simple solutions available for solving this problem:

Use callout_init_mtx, callout_init_rw, or callout_init(foo, 0)

Callout functions associated with a lock are exempt from the race condition described above—as long as the associated lock is held before calling the callout management functions.

Use callout_drain to permanently cancel a callout function

Use callout_drain instead of callout_stop to permanently cancel a callout function. See, by waiting for the callout function to finish, you can’t destroy any ...

Get FreeBSD Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.