sem_init -> bus error

This is a discussion on sem_init -> bus error within the C Programming forums, part of the General Programming Boards category; I have done : Code: #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <stdio.h> #include<time.h> #include <semaphore.h> #include <unistd.h> int main() ...

  1. #1
    g_p
    g_p is offline
    Registered User
    Join Date
    Dec 2006
    Posts
    85

    sem_init -> bus error

    I have done :

    Code:
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/shm.h>
    #include <stdio.h>
    #include<time.h>
    #include <semaphore.h>
    #include <unistd.h>
    
    int main() {
    
    sem_t *sem;
    
    int shmid = shmget(4,3 * sizeof(sem_t),(IPC_CREAT | 0666));
    
    sem[0] = shmat(shmid,NULL,0);
    
     /* then i initialise those three semaphores and i get a bus error */
    
    
    sem_init(&sem[0][0]),1,1); 
    sem_init(&sem[0][1]),1,0); 
    sem_init(&sem[0][2]),1,0);
    
    }
    Why do i get a bus error when i initialise them?

    Thanks, in advance!

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    sem is just a simple pointer.
    in sem_init you access them as it were a 2d-array.
    Kurt

  3. #3
    g_p
    g_p is offline
    Registered User
    Join Date
    Dec 2006
    Posts
    85
    Well i replaced sem_t *sem by

    sem_t *sem[1] and i get the same error :

    Bus error

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    176
    did this compile for you?

    Code:
    sem_init(&sem[0][0]),1,1); 
    sem_init(&sem[0][1]),1,0); 
    sem_init(&sem[0][2]),1,0);
    1 open bracket, 2 closing brackets for each of those

  5. #5
    g_p
    g_p is offline
    Registered User
    Join Date
    Dec 2006
    Posts
    85
    did this compile for you?


    Code:
    sem_init(&sem[0][0]),1,1);
    sem_init(&sem[0][1]),1,0);
    sem_init(&sem[0][2]),1,0);
    1 open bracket, 2 closing brackets for each of those


    Well, i made a mistake while copying the file here.

    Finally, my shmget had a problem with the specific key 4, i changed it and there is no bus error!


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21