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 objects that it might need.

Note

We’ll walk through an example that uses callouts in Chapter 6.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.109.30