Re: [dylan] Stream locking (was: Method combinations as a design pattern for locking)

Bruce Hoult <[email protected]> Wed, 18 Dec 2013 15:47:41 +1300
Newsgroups gmane.comp.lang.dylan.gwydion.devel
Message-ID <CAMU+EkzO8gN9+q3DqTzHyGzEJK+9WEcpexv5_tRSUe3JK6a6ZA@mail.gmail.com>
stdout and stderr are obviously special cases. It seems to me that the best
correctness with the lowest impact on performance would be to specialize
these (but not other streams) at a lower level than format(), not at a
higher level (e.g. format-out). Putting actual bytes (not characters) into
the buffer would be the right place.

Ideally:

- buffer stdout and stderr on a per thread basis.
- when a thread's buffer becomes full, take a lock and flush the buffer up
to and including the last newline, if any (otherwise the whole thing).
- force-out() and force-err() should of course flush everything

An alternative would be to take the lock and flush on every newline, but
that's too expensive when writing large amounts to a file or pipe.

Some platforms offer thread-local storage. On others (and maybe even on
those with it) you could have the buffer code itself maintain a mapping
from thread-id to the buffer for that thread. A hash table supplemented by
a single-element cache for the last thread should be fine.

Assuming getting the thread-id is cheap (or some proxy for it ... stack
base or similar).


On Wed, Dec 18, 2013 at 3:34 PM, Bruce Mitchener
<[email protected]>wrote:

> On Wed, Dec 18, 2013 at 9:31 AM, Bruce Hoult <[email protected]> wrote:
>
>> On Wed, Dec 18, 2013 at 3:23 PM, Ingo Albrecht <[email protected]>wrote:
>>
>>> Making format-out (and force-out) into locking wrappers would be a
>>> workable compromise for me.
>>>
>>
>> I don't tend to write programs which write to stdout from more than one
>> thread. Debug output to stderr, on the other hand...
>>
>
> A patch adding format-err and force-err to the format-out module of io
> will be welcome. (It would need to include documentation as well, but
> that's easy.)
>
>  - Bruce
>
>
> _______________________________________________
> hackers mailing list
> [email protected]
> https://lists.opendylan.org/mailman/listinfo/hackers
>
>

_______________________________________________
hackers mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/hackers