ptg10805159
938 Solutions to Selected Exercises Appendix C
Instead, when a linked list is built in a shared memory segment, the list pointers
should be stored as offsets to other objects in the shared memory segment. These
offsets areformed by subtracting the start of the shared memory segment from
the actual address of the object.
15.14 FigureC.21 shows the relevant events.
Parenti Childi Shared value update
set to set to set to returns Comment
0initialized bymmap
1child runs first, then is blocked
0parent runs
1
0then parent is blocked
2child resumes
1
3then child is blocked
2parent resumes
3
2then parent is blocked
4
3
5then child is blocked
4parent resumes
Figure C.21 Alternation between parent and child in Figure15.33
Chapter 16
16.1 FigureC.22 shows a program that prints the system’s byte order.
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int
main(void)
{
uint32_t i=0x04030201;
unsigned char *cp = (unsigned char *)&i;
if (*cp == 1)
printf("little-endian\n");
else if (*cp == 4)
printf("big-endian\n");
else
printf("who knows?\n");
exit(0);
}
Figure C.22 Determine byte order on system