-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathremovefilesemaphore.m
56 lines (48 loc) · 1.27 KB
/
removefilesemaphore.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function removefilesemaphore(semaphore)
%REMOVEFILESEMAPHORE Remove semaphore after file access.
% REMOVEFILESEMAPHORE(SEMAPHORE) removes the semaphore(s) set by function
% SETFILESEMAPHORE to allow file access for other Matlab processes.
%
% Example:
% sem = setfilesemaphore('test.mat');
% % access file test.mat here
% dir test.mat.semaphore.*
% removefilesemaphore(sem);
%
% Markus Buehren
% Last modified 07.04.2008
%
% See also SETFILESEMAPHORE.
import multicore.*
checkWaitTime = 0.1;
showWarnings = 0;
% remove semaphore files
for fileNr = 1:length(semaphore)
if existfile(semaphore{fileNr})
% do not use function deletewithsemaphores.m here!
% sometimes deletion permission is not given, so try several times to
% delete the file
warnID = 'MATLAB:DELETE:Permission';
warnState = warning('query', warnID);
warning('off', warnID);
fileDeleted = false;
for attemptNr = 1:10
lastwarn('');
try
delete(semaphore{fileNr}); %% file access %%
if isempty(lastwarn)
fileDeleted = true;
break
end
catch
% wait before checking again
pause(checkWaitTime);
end
end
warning(warnState);
if showWarnings && ~fileDeleted
% try one last time with display of warning message
delete(semaphore{fileNr});
end
end
end