Discussion:
immutable and RC
(too old to reply)
Marco Leise via Digitalmars-d
2014-10-15 05:04:06 UTC
Permalink
Is it possible to write a wrapper for file handles, that is
immutable if we don't plan to swap out the handle and the ref
count is in some external data structure and only accessed
in ctors/dtors of the struct ?
It would look quite a bit like some sort of head immutable,
but with no access to the mutable parts.

The motivation is that immutable is inherently shared, so it
simplifies code where a file handle might be used by several
threads but synchronization is ensured by the operating system
or at a higher level in our code.
(Otherwise one would have to reimplement read, write,
handle, ... with the exact same code, but `shared` attached or
cast away `shared`, which is wrong.)
--
Marco
Marco Leise via Digitalmars-d
2014-10-15 05:04:06 UTC
Permalink
Is it possible to write a wrapper for file handles, that is
immutable if we don't plan to swap out the handle and the ref
count is in some external data structure and only accessed
in ctors/dtors of the struct ?
It would look quite a bit like some sort of head immutable,
but with no access to the mutable parts.

The motivation is that immutable is inherently shared, so it
simplifies code where a file handle might be used by several
threads but synchronization is ensured by the operating system
or at a higher level in our code.
(Otherwise one would have to reimplement read, write,
handle, ... with the exact same code, but `shared` attached or
cast away `shared`, which is wrong.)
--
Marco
Kagamin via Digitalmars-d
2014-10-16 11:27:28 UTC
Permalink
A file handle is usually a plain integer, it doesn't make much
sense to annotate it with attributes.

Continue reading on narkive:
Loading...