#include <stdio.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>

typedef struct _g_shm_addr
{
    unsigned int is_dirty;
	unsigned int serv_num;
    unsigned int thread_number[1024];
} g_shm_t;

int main()
{
	g_shm_t *g_shm_ptr;

	void *shared_memory = (void *)0;
	int shmid;
	int i;

	shmid = shmget((key_t)6677, sizeof(g_shm_t), IPC_CREAT);
	if (shmid == -1)
	{
		exit(EXIT_FAILURE);
	}
	shared_memory = shmat(shmid, (void *)0, 0);
	if (shared_memory == (void *)-1)
	{
		exit(EXIT_FAILURE);
	}
	g_shm_ptr = (g_shm_t *)shared_memory;

	fprintf(stdout, "##############################\n");

	/*
	g_shm_ptr->is_dirty = 1;
	g_shm_ptr->is_dirty2 = 1;
	for (i=0; i < 10; i++)
	{
		g_shm_ptr->thread_number[i] = 1;
	}
	*/
	sleep(1);
//	while(1)
//	{
		fprintf(stdout, "### IS_DIRTY VALUE ==>> %d ###\n", g_shm_ptr->is_dirty);
		fprintf(stdout, "### IS_DIRTY2 VALUE ==>> %d ###\n", g_shm_ptr->serv_num);
		for (i=0; i < 10; i++)
		{
			fprintf(stdout, "### THREAD(%d) DIRTY VALUE ==>> %d ###\n", i, g_shm_ptr->thread_number[i]);
		}
//		usleep(1000);
//		fflush(stdout);
//	}

	if (shmdt(shared_memory) == -1)
	{
		exit(EXIT_FAILURE);
	}
	exit(EXIT_SUCCESS);
}
