Ejemplo n.º 1
0
int main(void)
{
	shm_name[0] = 't';
	shm_name[1] = 'e';
	shm_name[2] = 's';
	shm_name[3] = 't';
	size = 4;
	shm_addr = my_shm_create (shm_name, size);
	shm_addr = my_shm_open (shm_name);
	
	*shm_addr = 0;
	printf ("1\n");
	*shm_addr = 1;
	while(*shm_addr != 0)
	{}
	printf ("3\n");
	*shm_addr = 1;
	while(*shm_addr != 0)
	{}
	printf ("5\n");
	*shm_addr = 1;
	while(*shm_addr != 0)
	{}
	
	CloseAndUnlink();
	return (0);
}
Ejemplo n.º 2
0
void
initSemSHM(int pid)
{
    printf ("\n");
    #ifdef VERBOSE
    printf("Creating flags semaphore for procces %d\n", pid);
    #endif
    
    sem_flags = sem_open (sem_flags_name, O_CREAT | O_EXCL, 0600, 1);
    
    #ifdef VERBOSE
    if (sem_flags == SEM_FAILED)
    {
        perror ("ERROR: sem_open() failed");
    }
    printf("Creating sync semaphore for procces %d\n", pid);
    #endif
    
    sem_sync = sem_open (sem_sync_name, O_CREAT | O_EXCL, 0600, 0);
    
    #ifdef VERBOSE
    if (sem_sync == SEM_FAILED)
    {
        perror ("ERROR: sem_open() failed");
    }
    printf ("Creating Shared memory '%s' \n", shm_name);
    #endif
    
    shm_addr = my_shm_create (shm_name, SHM_SIZE);
    shm_addr[0] = flags; // make sure it's 0;
}
Ejemplo n.º 3
0
extern int 
main (int argc, char * argv[])
{
    int     rtnval;

	#ifdef VERBOSE
        printf ("Verbose output\n");
    #endif

    // Create a shared memory.
    shm_addr = my_shm_create (shm_name, SHM_SIZE);
    printf ("\nShared memory name '%s' is created. \n\n", shm_name);
    set_turn(0);

    wait_for_turn(0);
	printf ("1\n");
	set_turn(1);

	wait_for_turn(0);
	printf ("3\n");
	set_turn(1);

	wait_for_turn(0);
	printf ("5\n");
	set_turn(1);

	wait_for_turn(0);

	// Close the shared memory
    printf ("\nCalling close(%#x)", shm_fd);
    rtnval = close (shm_fd);
    if (rtnval != 0)
    {
        perror ("ERROR: close() failed");
    }
    printf (" -> returned %d\n", rtnval);
    shm_fd = -1;

    // Unlink the shared memory so it can be removed (reference counting)
    printf ("Calling shm_unlink('%s')", shm_name);
    rtnval = shm_unlink (shm_name);
    if (rtnval != 0)
    {
        perror ("ERROR: shm_unlink() failed");
    }
    printf (" -> returned %d\n", rtnval);

    // Close the program
    printf ("\nBye bye. Hope to see you soon.\n");
    return 0;	
}
Ejemplo n.º 4
0
Archivo: 1.c Proyecto: JoeryH/IPC32
void main(void) {
    int *      flag = (int *)my_shm_create("h_sync", sizeof(int));
    *flag = 0;
    int i = 1;
    for (; i < 6; i+=2) {
        while (*flag != 0) {
          
        }
        printf("%i\n", i);
        *flag = 1;
    }
    while (*flag != 0) {} //wait for exit
    
}