Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Multithreading support in pluggable module, but with problems
- X-seq: zsh-workers 40528
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Multithreading support in pluggable module, but with problems
- Date: Sat, 11 Feb 2017 11:46:32 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version; bh=G+c6HlsWI094cnRepHSS51KcFhbKMV+mYtdGQd2ePp8=; b=dhQdnKPlbYKqpLaiIYsPFvIt2ULhwZoJ8arJHEbfWfAR1wc/7n3jxcngVqv3kfdNFo 2FgjXlQ0DZ/HI90Y0CwZyRK/eVbm5aDa4tabBArm9juy8QfqCE2v4mLLF4B5/3/4qxs+ J3NX2MBVDB7OGUwYbsUgQtom0F7PH9NCwER/OIyruvbG5POx0w7c+AIZ4lUc+Km6rouV xYy3fzRd57ok1dPsV4/OsRCXflS5tmCZeiT2O71UCIe95QGIzwUz9ffrdMkYTcwQ8VQZ MquHloNtLhEP9PbdvfaD5ZXeNhO/I31o7g4ARVpTEBdkU2ZdCiEcqDjOORiy4ev4IShv +DxA==
- In-reply-to: <1486817916.2745591.877718432.2CE18595@webmail.messagingengine.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <1486817916.2745591.877718432.2CE18595@webmail.messagingengine.com>
On Feb 11, 4:58am, Sebastian Gniazdowski wrote:
} Subject: Multithreading support in pluggable module, but with problems
}
} # zpin 'print -rl "a:b" "c:d"' | zpopulator -A my_hash
}
} This is done entirely in background. zpin does fork() and this way makes
} Zsh think it's finished - main process exits. zpopulator starts a thread
} and makes main thread exit - this is also sufficient to make Zsh think
} that there is no background job.
So if I understand this correctly, you're attempting to use POSIX threads
to share the my_hash variable between the main shell and a 2nd thread of
which the main shell is not aware, so that the 2nd thread can stuff a
value into my_hash while the main thread goes on about its business?
I can almost promise you there is no way to make that work, at least not
in a crash-proof manner. Even making my_hash PM_READONLY -- which is I
presume what yesterday's question was about -- what is there to stop
the thread-unaware main shell from accessing it at a time when the 2nd
thread is changing it in some way that will send the main thread off
into uncharted memory?
Aside from that, you're running directly afoul of the presecribed
behavior of file descriptor management for shells, which amounts
to a prohibition on passing unexpected file descriptors down to any
forked children. If you want to keep a descriptor around, you have
to manipulate it with the routines in Src/utils.c that manage the
fdtable array.
In particular you *might* need to call either movefd() or redup()
rather than call dup2() directly, and you should otherwise be using
addmodulefd() to protect the fd from exec.c:closeallelse(). Examples
in Src/Modules/tcp.c.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author