Hello,
I have entered the forbidden land ruled by multi-threading and mutexes, and would like to ask for help.
I am using first_solution/3 to find a solution to my problem as follows:
program(Goal):-
mutex_create(myMutex),
first_solution(_, [strategy_1(Goal, myMutex), strategy_2(Goal, myMutex)], []).
strategy_k(Goal, Mutex):-
% Stuff K
with_mutex(Mutex, read_text_file(SomeFile))
% More stuff K
The threads created by first_solution/3 need to access a text file; and without using a mutex to protect access to the file, IO errors are raised. My mutex solution is the one above but it does not seem to work. Only the first thread is able to access the text file (Text-file access happens inside read_text_file/1
above using see/1, read/1, and seen/0).
Could you please walk me through fixing this?
Thanks.