C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-04-2003, 05:55 PM   #1
Registered User
 
Join Date: Sep 2003
Posts: 224
Fun with semaphores

The following is the code my professor used to initialize a semaphore, but I have some doubts:
Code:
void Init (int semid, int value)
{
	union {
		int val;
		struct semid_ds *buf;
		u_short *array;
	} arg;
	
	arg.val = value;
	if (semctl (0, semid, SETVAL, arg) < 0)
		perror ("semctl SETVAL");
	return;
}
Why didn't he just do semctl(semid, value, SETVAL)? According to the man pages, a semaphore is specified by semid and semnum, and presumably semid is the semaphore ID and semnum is the initial value of the semaphore. My confusion is confounded by the fact that the fourth argument to Init takes a union in which one of the fields is val--the value for SETVAL. Is his implementation right? The down and up operations are performed on semaphore specified by semid.
Yasir_Malik is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Semaphores, need advice on implementation. Swerve C++ Programming 2 01-13-2009 01:54 AM
semaphores Dr Spud C Programming 7 09-22-2007 12:45 PM
Semaphores Problems mhelal Linux Programming 2 05-06-2007 10:36 PM
Semaphores edk C++ Programming 1 11-25-2001 03:55 PM


All times are GMT -6. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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