Hacker News new | past | comments | ask | show | jobs | submit login

Workaround:

    #define LOCK(mutex) lock lock##__LINE__(mutex)
Or even C compatible scoped locks:

    #define SCOPED_LOCK(mutex) \
        for (int i##__LINE__ = lock_mutex(mutex), 1; \
                 i##__LINE__ --; \
                 unlock_mutex(mutex))
Use like

    SCOPED_LOCK(foo->mutex) {
        do_stuff();
    }



Of course there are workarounds, but that's not the point. First of all, your solution requires macros and the problems that come with that, but also, you now require programmers to remember to use your macro instead of just declaring the instance.

The problem I'm describing is less about the effort of adding a variable name -- that's really not a big deal -- its that its super error prone to remember and these bugs slip through all the time. Requiring a variable name (either explicitly or through a macro like yours) is error prone.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: