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

Unless you use a "lock inc", increment is semantically a read-modify-write, so I believe those steps can technically happen on x86. However, since a thread cannot be interrupted in the middle of an instruction, it's very unlikely that 9999 operations can happen in one thread while another executes an increment. If you wrote it as a mov, an add, and another mov, all it would take is a context switch at exactly the right time.

On the other hand, 20000 is unlikely as well, if the threads have any concurrency at all.




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

Search: