Virtual Address Space
- Posted by Al Getz <xaxo at AOL.COM> Nov 10, 2000
- 446 views
I ran across something peculiar when working with multiple threads, i was wondering if anyone had any ideas on this: for example: In the following two programs, program1 allocates a single byte in memory, fills the byte with the number 2, and then calls a second program passing the address of the byte. It then waits for user to type a key before freeing the original byte allocated. The called program, program2, attempts to read the original byte using the address passed from the first program. The address is printed out byte by byte in both programs in order to verify that the address was passed successfully. program1.exe contains bindw code: include get.e atom addr,i sequence AddrString addr=allocate(1) --one byte poke(addr,2) --poke the number 2 at addr ?peek(addr) --prints a "2" as expected AddrString=sprintf("%f",addr) --convert addr to string to pass ?int_to_bytes(addr)--print out addr as 4 bytes system("program2.exe "&AddrString,0) --call program2.exe (below) --passing AddrString i=wait_key() free(addr) program2.exe contains bindw code: include GetCommLineParams.e --just function to return param strings atom i,addr sequence AddrString AddrString=GetCommLineParams(1)--gets string param #3 (passed address) AddrString=value(AddrString) if AddrString[1]=GET_SUCCESS then addr=AddrString[2] --now contains original addr end if ?int_to_bytes(addr)--prints out addr as 4 bytes for verification --this always prints out exactly as in program1.exe --so i assume it was passed successfully. ?peek(addr) --this never prints out the original byte poked, but --also does not generate an access exception i=wait_key() The peculiar thing here is that although the byte cant be read successfully in the second program, it doesnt generate an exception or any error of any kind. Just quietly returns the wrong value every single time. Any other thoughts or comments on this? Thanks, Al