How to ensure two docker containers don’t process the same file?

So I have two services A and B in a swarm. A has 5 instances and so does B. They both access files from a common mount. If I put a 100 files in this mount, how do I ensure that the files A and B pick (maybe 50 each) are mutually exclusive i.e the file doesn’t get processed twice? Additionally how would i ensure this for two instances of the same service?

Source: StackOverflow