News for hackers. Stuff that matters.
Re:Why Is SQLite Coded in C? (2017) by falcolas on Wednesday March 14, 2018 @06:49PM (#16589064)
> Sure, you need to remember to release that lock and free that memory

It's always bothered me how complex of an operation people seem to think this is.

    errno = pthread_mutex_lock(&m);
    if (errno == 0) {
       do_something();
       pthread_mutex_unlock(&m);
    }
Short of a segfault or 'do_something' doing something really, unusually stupid, you can't avoid freeing the mutex.
Re:Why Is SQLite Coded in C? (2017) by blub on Thursday March 15, 2018 @04:08AM (#16591124)
Yeah, most projects don't consist of a single function locking and unlocking a mutex. :) Try doing the same in five 200 LOC functions with multiple returns when three different threads are sharing the data, for 10 years, with a yearly personnel turnover of 20%.
Re:Why Is SQLite Coded in C? (2017) by falcolas on Thursday March 15, 2018 @09:31AM (#16592647)
Been there done that, fought similar problems. Deadlocks abound.

Only difference? We were in Python.

Re:Why Is SQLite Coded in C? (2017) by aidenn0 on Thursday March 15, 2018 @02:38AM (#16590857)
Something really unusually stupid like returning from the function (assuming do_something() is a standin for arbitrary code, not specifically a function call)?

This is not even remotely the worst thing about mutexes though, so it wouldn't be why I would suggest avoiding them.

Re:Why Is SQLite Coded in C? (2017) by falcolas on Thursday March 15, 2018 @09:39AM (#16592705)
Honestly, to help avoid mistakes, I would keep it as a function call. Sure, it adds to the stack depth, but it also ensures a separate return doesn't cause the lock to be lost.

There's also the goto pattern, but anytime you separate a lock from an unlock by more than a screen's worth of text, they're forgotten.

Re:Why Is SQLite Coded in C? (2017) by aidenn0 on Thursday March 15, 2018 @01:40PM (#16594919)
And inline functions don't even add stack depth. It's still something that happens manually though. Every item that needs to be done manually and doesn't cause obvious failures when not done adds to development costs.