zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <psprint2@fastmail.com>
To: zsh-workers@zsh.org, Bart Schaefer <schaefer@brasslantern.com>
Subject: Re: When is mem.c / malloc called?
Date: Fri, 10 Feb 2017 11:45:38 -0800	[thread overview]
Message-ID: <1486755938.1593082.877179952.42D3C472@webmail.messagingengine.com> (raw)
In-Reply-To: <170210102523.ZM28915@torch.brasslantern.com>

On Fri, Feb 10, 2017, at 10:25 AM, Bart Schaefer wrote:
> } I'm writing a module that needs thread safe memory allocation.
> 
> This sounds pretty dangerous, as the rest of zsh (signal handling in
> particular, update of the environment on e.g. "export", etc.) is not
> going to be thread-safe.
> 

I've ended up copying multiple Zsh functions, calling them
my_{original_name}, creating separate call tree. The goal is to do this
in multi-threaded manner:

# print -rl -- "a,b" "c,d" | zpopulator -D , -vA myhash
# typeset -p myhash
typeset -A myhash=( a b c d )

I basically create a thread after I do:

fdopen( dup( fileno( stdin ) ), "r" );

in module's builtin – zpopulator. I was counting on: Zsh will think
module command ended because main thread will do "return 0", it will not
break the pipe because it gets broken by itself when reader or writer
exits. This way the forked "print -rl" and the thread-splitted
"zpopulator" could work in background. However I just discovered that:

# ls -R / | zpopulator -D , -vA myhash

DOES block shell.. I successfully obtained no-block behavior but it was
zpopulator that was persisting, not the writing process (forked one). 

Have you any idea how to cause above to not block shell? zpopulator's
thread exits from module's builtin, this should be close to unblock
shell..

Code:
https://github.com/psprint/zpopulator/blob/41f40f7b35c67fed907d660b620f4ec5bda6022e/module/Src/psprint/zpopulator.c#L438-L442

-- 
Sebastian Gniazdowski


      reply	other threads:[~2017-02-10 19:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 12:24 Sebastian Gniazdowski
2017-02-10 15:17 ` Sebastian Gniazdowski
2017-02-10 18:11   ` Bart Schaefer
2017-02-10 18:25 ` Bart Schaefer
2017-02-10 19:45   ` Sebastian Gniazdowski [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1486755938.1593082.877179952.42D3C472@webmail.messagingengine.com \
    --to=psprint2@fastmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).