minor enhance: use __sync_add/sub_and_fetch to replace pthread locking