it seems not possible to use (share) with packed elements.
i.e.
(set 'flash (share))
(share flash (pack (dup "u" 10) (sequence 1 10)))
According to the docs (share) should work with any newlisp expression.
When forking processes and calling C-libs from these processes it would be nice to be able to set the (share) in the parent process without the neccessity to repack it in the child process.
Or do i miss something obvious here ?
Regards
Heiko
(share) with (pack) memory
Re: (share) with (pack) memory
Perhaps you forgot to unpack when reading the information back.
The above works for me on macOS, Linux, FreeBSD and Windows.
Ps: also included a qa-specific-tests/qa-share in the newlisp-10.7.4.tgz source distribution here: http://www.newlisp.org/downloads/develo ... nprogress/
Code: Select all
> (set 'flash (share))
4419780608
> (share flash (pack (dup "u" 10) (sequence 1 10)))
"\001\000\002\000\003\000\004\000\005\000\006\000\007\000\b\000\t\000\n\000"
> (unpack (dup "u" 10) (share flash))
(1 2 3 4 5 6 7 8 9 10)
>
Ps: also included a qa-specific-tests/qa-share in the newlisp-10.7.4.tgz source distribution here: http://www.newlisp.org/downloads/develo ... nprogress/
Re: (share) with (pack) memory
hm, i meant reading the (shared memory) from a C-lib.
i.e.
Parent <-> (share mem) <-> Forked child (calling the C-lib)
Parent:
(set 'flashMemory (share))
(share flashMemory (rand 0xFFFF 100))
Forked Child:
(emulavr_load_flash (pack (dup "u" 100) flashMemory))
C-lib prints rubbish numbers:
ubyte * emulavr_load_flash(ubyte * flash_prom) {
printf("EMULAVR FLASH intro: 0x%04X 0x%04X\n", flash_prom[0],flash_prom[1]);
}
i.e.
Parent <-> (share mem) <-> Forked child (calling the C-lib)
Parent:
(set 'flashMemory (share))
(share flashMemory (rand 0xFFFF 100))
Forked Child:
(emulavr_load_flash (pack (dup "u" 100) flashMemory))
C-lib prints rubbish numbers:
ubyte * emulavr_load_flash(ubyte * flash_prom) {
printf("EMULAVR FLASH intro: 0x%04X 0x%04X\n", flash_prom[0],flash_prom[1]);
}
Re: (share) with (pack) memory
In this changed example from newlisp-10.7.4/qa-specific-tests/qa-share share is used by a spawned process:
spawn is based on fork internally. There is an example newlisp-10.7.4/example/prodcons.lsp that uses fork directly.
If your example tries to retrieve packed shared memory, it's wrong:
the correct syntax would be:
if you pack for storing, you have too unpack, and the content cannot be accessed directly via 'flashMemory' but using '(share flashMemory)'.
Code: Select all
(set 'flash (share))
(share flash (pack (dup "u" 10) (sequence 1 10)))
(define (get-data adr)
(unpack (dup "u" 10) (share adr)))
(spawn 'X (get-data flash))
(sync 10)
(println X " = " (sequence 1 10))
(if (= X (sequence 1 10))
(println "test passed SUCCESSFUL")
(println "test passed with error"))
If your example tries to retrieve packed shared memory, it's wrong:
Code: Select all
(pack (dup "u" 100) flashMemory)
Code: Select all
(unpack (dup "u" 100) (share flashMemory))