Is counter_cache transaction safe?

In one of the web applications I’ve developed, counter_cache get out
of sync from time to time.

Doesn’t the counter method lock the row of the parent table before
inserting new record into the child table?

daesan.