#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/errno.h>
#include <fcntl.h>

int mask[] =
	{
		0x0001,
		0x0002,
		0x0004,
		0x0008,
		0x0010,
		0x0020,
		0x0040,
		0x0080,
		0x0100,
		0x0200,
		0x0400,
		0x0800,
		0x1000,
		0x2000,
		0x4000,
		0x8000
	};

#define Assert(condition) \
{ \
	if (!(condition)) \
	{ \
		int *ip = NULL; \
		fprintf(stderr, "Assertion FAILED\n"); \
		*ip = 1; \
	} \
}
	
	
main(int argc, char *argv[])
{
	int shmid;
	int *buf;
	int procid = atoi(argv[1]);
	
	errno = 0;
	if ((shmid = shmget(0x101, 16, IPC_CREAT | 0x01FF)) == -1)
		perror("shmget failed");
	
	if ((buf = (int *)shmat(shmid, NULL, 0)) == -1)
		perror("shmat failed");

	if (procid == 0)
		buf[0] = 0;

	for (;;)
	{
		buf[0] |= mask[procid];
		Assert(buf[0] & mask[procid]);
		buf[0] &= ~mask[procid];
		Assert(!(buf[0] & mask[procid]));
	}
}
		
	
