Feh / nocache

minimize caching effects
BSD 2-Clause "Simplified" License
554 stars 53 forks source link

BUG: pthread_mutex_lock on destroy #51

Closed pavlinux closed 2 years ago

pavlinux commented 2 years ago

https://github.com/Feh/nocache/blob/2b6ea1f6b46dabd08db6c6b8be78874b90ecfd22/nocache.c#L207

May be unlock ? ))

Feh commented 2 years ago

No… you have to lock the mutexes so that you can guarantee no-one else is depending on them and the protected data being there, before freeing them…?

pavlinux commented 2 years ago

In general, the entire destroy() function is useless, except for two free()

Feh commented 2 years ago

destroy() and its attempt to clean up would be “useless” if the following conditions were true:

For most even slightly more complicated programs, these conditions don’t generally hold.

You can see the reasoning in the original commit that introduced it: https://github.com/Feh/nocache/commit/d355dafdae2d382bf4af60252e53174718d73698

If you are worried about the constant overhead the destroy() function introduces, feel free to add some getenv() type call in there to optionally skip cleanup steps.