node.jstaffydb

Can race conditions exist with TaffyDB and node.js?


Can a race condition exist within TaffyDb and nodejs? For example: 100 concurrent connections with node.js using require('net') reliable data read relies on a variable Dbman(example) lock: to be 0 when not being read and 1 when being read. Could the data be read and therefor corrupted if 2 reads were called just before the lock to be set?


Solution

  • Node.js programs are JavaScript programs, and as-such, there is no multi-threading.

    Each function runs from a SINGLE dispatch loop thread, so If you set a variable to a specific value it is guaranteed to remain that value through the whole execution of that function call.

    While a single function is executing no other functions can run, therefore the race condition you are considering is impossible.