vendredi 27 février 2015

How can I deal with this race condtion

Let's say, I'm using cluster to handle the multiple cpus case. Unfortunately, I got a race condition when I tried to rename a file when its siblings are modified.



var cluster = require('cluster'),
fs = require('fs');
if(cluster.isMaster){
for(var i=0;i<3;i++){
cluster.fork();
}
}else{
fs.watch('/home/project',function(){
fs.rename('/home/project/file1.js','/home/project/module1.js',function(er){
if(er){
throw er; //Error: ENOENT, rename '/home/project/file1.js'
}
});
});
fs.appendFile('/home/profile/file2.js','some data',function(er){
if(er){
throw er;
}
});
}


How can I prevent this race condition?


Aucun commentaire:

Enregistrer un commentaire