Skip to content

Instantly share code, notes, and snippets.

@5HT
Last active July 30, 2025 06:19
Show Gist options
  • Save 5HT/74904f8d33a967bc88a2b22af3e160e7 to your computer and use it in GitHub Desktop.
Save 5HT/74904f8d33a967bc88a2b22af3e160e7 to your computer and use it in GitHub Desktop.
Semaphore Implementation in TRON, QNX, BeOS and NuttX
Let's Write Scientific Article About Comparison of Semaphore Implementation in different Real-Time OS: TRON, QNX, BeOS, NuttX:
Our Intention is to buils refined API on all thoese API to achieve best real-time performance and idiomatic implementation.
Could you propose your version of Real-Time Semaphore implementation that is far better in terms of provability
of correcntess (simplicity) and performance?
BeOS:
status_t acquire_sem(sem_id sem);
status_t acquire_sem_etc(sem_id sem, uint32 count, uint32 flags, bigtime_t timeout);
sem_id create_sem(uint32 thread_count, const char * name);
status_t delete_sem(sem_id sem);
status_t get_sem_count(sem_id sem, int32* thread_count);
status_t get_sem_info(sem_id sem, sem_info* info);
status_t get_next_sem_info(team_id team, uint32* cookie, sem_info* info);
status_t release_sem(sem_id sem);
status_t release_sem_etc(sem_id sem, int32 count, uint32 flags);
status_t set_sem_owner(sem_id sem, team_id team);
typedef struct sem_info {
sem_id sem;
team_id team;
char name[B_OS_NAME_LENGTH];
int32 count;
thread_id latest_holder;
}
NuttX:
int sem_init(sem_t *sem, int pshared, unsigned int value)
int sem_destroy(sem_t *sem)
sem_t *sem_open(const char *name, int oflag, ...)
int sem_close(sem_t *sem)
int sem_unlink(const char *name)
int sem_wait(sem_t *sem)
int sem_timedwait(sem_t *sem, const struct timespec *abstime)
int sem_trywait(sem_t *sem)
int sem_post(sem_t *sem)
int sem_getvalue(sem_t *sem, int *sval)
int sem_getprotocol(FAR const pthread_mutexattr_t *attr, FAR int *protocol)
int sem_setprotocol(FAR pthread_mutexattr_t *attr, int protocol)
TRON:
typedef struct semaphore_control_block {
QUEUE wait_queue; /* Semaphore wait queue */
ID semid; /* Semaphore ID */
void *exinf; /* Extended information */
ATR sematr; /* Semaphore attribute */
INT semcnt; /* Semaphore current count value */
INT maxsem; /* Semaphore maximum count value */
} SEMCB;
EXPORT ER knl_semaphore_initialize( void )
SYSCALL ID tk_cre_sem( CONST T_CSEM *pk_csem )
SYSCALL ER tk_del_sem( ID semid )
SYSCALL ER tk_sig_sem( ID semid, INT cnt )
LOCAL void sem_chg_pri( TCB *tcb, INT oldpri )
LOCAL void sem_rel_wai( TCB *tcb )
SYSCALL ER tk_wai_sem( ID semid, INT cnt, TMO tmout )
SYSCALL ER tk_ref_sem( ID semid, T_RSEM *pk_rsem )
EXPORT ER knl_semaphore_getname(ID id, UB **name)
SYSCALL INT td_lst_sem( ID list[], INT nent )
SYSCALL ER td_ref_sem( ID semid, TD_RSEM *pk_rsem )
SYSCALL INT td_sem_que( ID semid, ID list[], INT nent )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment