9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Giacomo Tesio <giacomo@tesio.it>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] Privalloc(2) and rfork(RFPROC|RFMEM) (was: a pair nec bugs)
Date: Sat,  5 Sep 2015 16:11:44 +0200	[thread overview]
Message-ID: <CAHL7psGwpPEeyqynnLRmuXp-dOdGV1XzMywNui08vTMDt7q63A@mail.gmail.com> (raw)
In-Reply-To: <CAHL7psF6pK75inCaCd==Ay0eGmOm+QsqBjW2pM1F7HyTaWkNLg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1807 bytes --]

... and given getpid(2) implementation, a pid based table could be quite
expensive, since MyStruct is accessed very very often.

2015-09-05 16:03 GMT+02:00 Giacomo Tesio <giacomo@tesio.it>:

> 2011-05-20 3:30 GMT+02:00 erik quanstrom <quanstro@quanstro.net>:
>
>> one note is that while i'm aware of privalloc(2), i didn't use it.  the
>> implementation doesn't appear correct for shared-memory procs.
>> i think there are two issues
>> - locking is unnecessary.  the only preemptable unit of execution is
>> a process and each process is guarenteed to have its own instance
>> of _privates and _nprivates.
>> - for shared-memory procs, we will run out of privates because
>> the static privinit will be falsely shared.  privinit should be replaced
>> by using a private entry.
>>
>
> In a set of processes that share memory, I need a single per-process
> location to store the address of structure (which is in turn allocated in
> the global memory space).
>
> Privalloc(2) seemed what I need, but seem that I can't use it properly.
>
> In the parent process I do:
>
> 1) initialialize a global variable p = (MyStruct **)privalloc();
> 2) allocate a MyStruct for every process I'm going to spawn
> 3) spawn processes with rfork(RFMEM|RFPROC)
>
> The spawn() function that call rfork takes a MyStruct* as argument and
> assign it to *p in the new process.
> For extra safety I added an assert(*p == nil) just after rfork, and after
> a few (apparently?) successful spawns, the assert fails.
>
> What I need is a sort of thread-local storage for the MyStruct*, so that
> each child process can find it's own dedicated MyStruct.
> I know that could get this with an hashtable based on the pid, but I'd
> prefer to avoid the book keeping if possible.
>
>
> Giacomo
>

[-- Attachment #2: Type: text/html, Size: 2639 bytes --]

  reply	other threads:[~2015-09-05 14:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-05 14:03 Giacomo Tesio
2015-09-05 14:11 ` Giacomo Tesio [this message]
2015-09-05 15:27 ` erik quanstrom
2015-09-05 16:41   ` erik quanstrom
2015-09-05 18:42     ` Giacomo Tesio
2015-09-05 18:47       ` erik quanstrom
2015-09-05 23:03         ` Giacomo Tesio
2015-09-05 18:56       ` cinap_lenrek
2015-09-05 22:45 ` Charles Forsyth
2015-09-05 23:38   ` cinap_lenrek
2015-09-06 13:14     ` erik quanstrom
2015-09-06 14:12     ` Charles Forsyth
2015-09-06 15:02       ` erik quanstrom
2015-09-06 20:21         ` Charles Forsyth
2015-09-07  0:30           ` erik quanstrom
2015-09-07  9:38             ` Charles Forsyth
2015-09-07 11:59               ` Charles Forsyth
2015-09-06 18:21       ` cinap_lenrek
2015-09-06 20:27         ` Charles Forsyth

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=CAHL7psGwpPEeyqynnLRmuXp-dOdGV1XzMywNui08vTMDt7q63A@mail.gmail.com \
    --to=giacomo@tesio.it \
    --cc=9fans@9fans.net \
    /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.
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).