Can I have a sem_t (semaphore) object take a开发者_高级运维n a value of more than 1? Since sem_post only increments by 1. Is there a sem_set?
Yes, a sem_t can take on a value of more than 1. You can use sem_init to initialise your semaphore to an abitrary value. Quoting from this link:
To initialize a semaphore, use sem_init():
int sem_init(sem_t *sem, int pshared, unsigned int value);
- sem points to a semaphore object to initialize
- pshared is a flag indicating whether or not the semaphore should be shared with fork()ed processes. LinuxThreads does not currently support shared semaphores
- value is an initial value to set the semaphore to
Example of use:
sem_init(&sem_name, 0, 10);
I'm not aware of any function that can increment a sem_t by an arbitrary value.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论