9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Privalloc(2) and rfork(RFPROC|RFMEM) (was: a pair nec bugs)
@ 2015-09-05 14:03 Giacomo Tesio
  2015-09-05 14:11 ` Giacomo Tesio
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Giacomo Tesio @ 2015-09-05 14:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

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

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: 2039 bytes --]

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2015-09-07 11:59 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-05 14:03 [9fans] Privalloc(2) and rfork(RFPROC|RFMEM) (was: a pair nec bugs) Giacomo Tesio
2015-09-05 14:11 ` Giacomo Tesio
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

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).