Are file mutexes available in Matlab these days?

조회 수: 19 (최근 30일)
Ben Wetherill
Ben Wetherill 2018년 1월 29일
편집: Steven Lord 2018년 1월 30일
I'm using Matlab 2016b. I looking at using the Parallel Pool to run a large number of simulations and post processing. The simulations are split into several classes, each with its own Excel result summary file. To ensure I don't get file access issues I want to use mutexes, but I've not been able to find anything about these being available in Matlab. I found some threads on here from people lamenting the lack of mutexes back in 2011, but maybe they have been implemented by now?
I'm aware of more clunky methods of doing this, such as using fopen() to see if the file is already open, but this doesn't give me the same protection a mutex lock would.

채택된 답변

Edric Ellis
Edric Ellis 2018년 1월 30일
Probably your best bet with the current implementation is to use a DataQueue. The plan would be to have the workers send the information to be saved back to the client using the send method of the DataQueue. The client would use afterEach to react to these incoming messages, and save the data to file. This means that only a single process is ever accessing the files - so no mutex required. Obviously there's cost associated with sending the data from the workers back to the client - but there's also cost involved with using a mutex to wait until it is safe to access the file.
  댓글 수: 3
Guillaume
Guillaume 2018년 1월 30일
편집: Steven Lord 2018년 1월 30일
parallel.pool.DataQueue requires R2017a or later, as documented on the bottom of its doc.
[SL: fixed typo in name of the object]
Ben Wetherill
Ben Wetherill 2018년 1월 30일
편집: Ben Wetherill 2018년 1월 30일
Darn! :(

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by