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


    #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__ --; \
Use like

    SCOPED_LOCK(foo->mutex) {

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