## winix-file-io-mutex.pkg
#
# The Mythryl standard.lib cross-platform "winix" file I/O
# library was written for a monothreaded system; it is not
# designed to resolve race conditions betweem parallel posix
# threads attempting to (say) simultaneously write to stdout.
#
# Handling such situations sanely requires using mutual
# exclusion ("mutex") support from the hostthread library.
#
# I expect posix-thread functionality to be used primarily
# internally within Mythryl libraries, rather than by the
# application programmer, and the form of that use is not
# yet clear to me.
#
# After some consideration, I decided that at present I do
# not wish to clutter the winix codebase with mutex wrappers,
# nor do I wish to create yet another set of parallel winix-*pkg
# files containing such wrappers, so for now I will settle for
# providing a global winix mutex here, which Mythryl library
# code may use when and where mutual exclusion is needed.
#
# Eventually we may want one mutex per file (say) for greater
# parallelism, but using a single mutex initially has the great
# virtual of minimizing deadlock risk, and disk I/O is anyhow
# so slow as to make speed considerations largely irrelevant.
#
# A typical use of this mutex will look like # For a live example see
src/lib/std/src/hostthread-unit-test.pkg
#
# stipulate
# package mtx = winix_file_io_mutex; # winix_file_io_mutex is from
src/lib/std/src/io/winix-file-io-mutex.pkg# package hth = hostthread; # hostthread is from
src/lib/std/src/hostthread.pkg# herein
#
# package hostthread_unit_test {
# #
# fun pline line_fn # Define a hostthread-safe function to output lines.
# = # "pline" is mnemonic for for "print_line" but also "parallel_print_line" and "hostthread_safe_print_line" and such. :-)
# hth::with_mutex_do mtx::mutex {.
# #
# line = line_fn () + "\n";
# #
# file::write (file::stdout, line );
# };
#
# < omitted code >
#
# pline . { sprintf "Fiddle %d faddle %d" foo bar; }; # Print narration line with proper mutual-exclusion vs other hostthreads.
#
# < omitted code >
#
# };
# end;
#
# -- 2012-03-10 CrT
# Compiled by:
#
src/lib/std/src/standard-core.sublibstipulate
package hth = hostthread; # hostthread is from
src/lib/std/src/hostthread.pkgherein
package winix_file_io_mutex {
# ===================
#
mutex = hth::make_mutex ();
};
end;