mercredi 27 juillet 2016

Passing semaphores as an argument to functions

I'm working on a static analysis tool which detects if a there's a mismatch for between lock/release calls for a semaphore. The detection is specific to VxWorks RTOS.

I came across this testcase and my tool detects this as mismatch between lock and release of semaphores because my implementation is solely based upon comparing the semaphore strings passed to the lock/release call.

void fun(char semid);
char id,i;
int main()
{
    id = semCreate();         //initializing a semaphore
    fun(id);
    semGive(id);              //semaphore release call
    return 0;
}
void fun(char semid)
{
    semTake(semid);          //semaphore lock call
    i++;        
}

Logically the code makes sense, but is this a correct way of using semaphores? Is this a regular programming practice or is it plainly invalid?

Some detailed code supporting or rejecting the usage of semaphores as given above would be highly appreciated.

Aucun commentaire:

Enregistrer un commentaire