int main() { SchedSet(NULL, NULL, SCHED_RR, NULL); SyncTypeCreate(_NTO_SYNC_SEM, &Semaphore, NULL); // initial count: 0 ThreadCreate(NULL, Thread1, NULL, NULL); ThreadCreate(NULL, Thread1, NULL, NULL); sleep(3); ThreadCreate(NULL, Thread2, NULL, NULL); SchedYield(); sleep(11); return(0); }
int sem_init(sem_t *sem, int pshared, unsigned int value) { struct _sync_attr attr; attr.__protocol = (int)value; attr.__flags = pshared ? PTHREAD_PROCESS_SHARED : PTHREAD_PROCESS_PRIVATE; attr.__prioceiling = 0; if(SyncTypeCreate(_NTO_SYNC_SEM, (sync_t *)sem, &attr) == -1) { if(errno == EAGAIN) { errno = ENOSPC; // To conform with POSIX 1003.1b } return(-1); } return(0); }
int SyncCreate(sync_t *sync, const struct _sync_attr *attr) { return SyncTypeCreate((unsigned)sync, (sync_t *)attr, 0); }