Link blog: C, threads, memory
Oct. 14th, 2021 12:13 am- Memory barriers in C
- What it says on the tin.
(tags: C memory threads)
Originally posted at Name and Nature. You can comment there (where there are currently comments) or here.
Originally posted at Name and Nature. You can comment there (where there are currently comments) or here.
Originally posted at Name and Nature. You can comment there (where there are currently comments) or here.
(tags: tools programming C)
enum my_things {
thing_this,
thing_that,
thing_other,
num_things
};void (*thing_fns[num_things])(void) = {
do_this,
do_that,
do_other
};
void do_thing(enum my_things current_thing)
{
thing_fns[current_thing]();
}
void do_this(void)
{
/* wibble */
}
/* etc, etc. */
my_things member to the middle of the list (perhaps you're listing your things in some order which makes sense in the context), go to update thing_fns, miscount how far down the definition thing_fns they've gone and screw up the ordering of the function pointers. Now the wrong function handles some (but not all) of the things, with hilarious results.num_things + 1. Now their array is sized correctly anyway.)