1) RPC
Mutex:
pthread_mutex_t
init_config_mutex = PTHREAD_MUTEX_INITIALIZER ;
pthread_mutex_lock(&init_config_mutex);
pthread_mutex_unlock(&init_config_mutex);
Semaphore:
1) int sem_init(sem_t *sem, int pshared, unsigned int value);
Initialise an unnamed semaphore.value is initial value of semaphore.
sem_t *p_sem;
int Success = FAIL;
Success = sem_init((sem_t *)p_sem, 0, semaphore_info->isemcnt);
int Success = FAIL;
Success = sem_init((sem_t *)p_sem, 0, semaphore_info->isemcnt);
2) sem_t *sem_open(const char *name, int oflag,
mode_t mode, unsigned int value);
initialize and open a named semaphore
mode_t mode, unsigned int value);
initialize and open a named semaphore
#define SHM_SEM_NAME
"/shm_sem"
temp_sem = sem_open(SHM_SEM_NAME, 0);
temp_sem = sem_open(SHM_SEM_NAME, 0);
3) int sem_post(sem_t *sem);
int sem_wait(sem_t *sem);
int sem_trywait(sem_t *sem);
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
sem_t* temp_sem = NULL;
temp_sem = sem_open(SHM_SEM_NAME, 0);
if (temp_sem == SEM_FAILED)
int sem_trywait(sem_t *sem);
int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout);
sem_t* temp_sem = NULL;
temp_sem = sem_open(SHM_SEM_NAME, 0);
if (temp_sem == SEM_FAILED)
if(sem_wait(temp_sem) <
0)
{
{
if(sem_post(temp_sem) <
0)
{
4) int sem_unlink(const char *name);
sem_unlink - remove a named semaphore
if(sem_unlink(SHM_SEM_NAME) < 0)
{
4) int sem_unlink(const char *name);
sem_unlink - remove a named semaphore
if(sem_unlink(SHM_SEM_NAME) < 0)
5) int sem_destroy(sem_t *sem); sem_destroy - destroy an unnamed semaphore ret_val = sem_destroy(p_sem);
6) int sem_close(sem_t *sem); return sem_close((sem_t *)p_sem);
Message Queue:
Supported by Operating
System.
1) mqd_t mq_open(const char *name, int oflag, mode_t
mode,
struct mq_attr *attr);
For first time, open with attribyte set.
struct mq_attr *attr);
For first time, open with attribyte set.
#define
MSGQOBJ_NAME_RX "/rpc_proc_RXQUEUE"
struct mq_attr msgq_attr, msgq_attr1;
msgq_attr.mq_maxmsg = numberof_msgs;
msgq_attr.mq_msgsize= msg_size;
:
struct mq_attr msgq_attr, msgq_attr1;
msgq_attr.mq_maxmsg = numberof_msgs;
msgq_attr.mq_msgsize= msg_size;
:
msgq_id =
mq_open(MSGQOBJ_NAME_RX, O_RDWR | O_CREAT , S_IRWXU | S_IRWXG,
&msgq_attr);
After that just open.
msgq_id =
mq_open(MSGQOBJ_NAME_RX, O_RDWR , S_IRWXU | S_IRWXG, NULL);
2) int mq_send(mqd_t mqdes, const char
*msg_ptr,
size_t msg_len, unsigned int msg_prio);
msgprio = 0;
ret_value = mq_send(msgq_id, ptr, length_of_msg, msgprio);
size_t msg_len, unsigned int msg_prio);
msgprio = 0;
ret_value = mq_send(msgq_id, ptr, length_of_msg, msgprio);
3) int mq_close(mqd_t mqdes);
ret_value = mq_close(msgq_id);
ret_value = mq_close(msgq_id);
4) ssize_t mq_receive(mqd_t mqdes, char *msg_ptr,
size_t msg_len, unsigned int *msg_prio);
unsigned int sender = 0;
msgsz = mq_receive(msgq_id, ptr , length_of_msg , &sender);
size_t msg_len, unsigned int *msg_prio);
unsigned int sender = 0;
msgsz = mq_receive(msgq_id, ptr , length_of_msg , &sender);
5) int mq_getattr(mqd_t mqdes, struct mq_attr
*attr);
mq_getattr(msgq_id,
&msgq_attr1);
6) int mq_unlink(const char *name);
mq_unlink(MSGQOBJ_NAME_TX);
mq_unlink(MSGQOBJ_NAME_TX);
7) ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
size_t msg_len, unsigned int *msg_prio,
const struct timespec *abs_timeout);
#define TIMEOUT_VALUE 180
struct timespec tm;
size_t msg_len, unsigned int *msg_prio,
const struct timespec *abs_timeout);
#define TIMEOUT_VALUE 180
struct timespec tm;
ret_value = clock_gettime(CLOCK_REALTIME, &tm);
if( ret_value != SUCCESS)
{
return FAIL;
}
tm.tv_sec += TIMEOUT_VALUE; //absolute timeout
msgsz = mq_timedreceive (msgq_id, ptr , length_of_msg , &sender,&tm);
if (msgsz == -1) {
SHARED_MEMORY:
int shm_open(const char *name, int oflag, mode_t mode);
int shm_unlink(const char *name);
FILE:
SIGNAL:
SOCKET:
Pthreads:
pthread_detach()
Which is best way to create
mutually exclusive access? In terms of efficeincey, multi-processor
environments..
mutex in case of
pthreads.
semaphore in case of kernel in
multiprocessor environments or spinlock in case of very short
processing.
1 comment:
https://users.pja.edu.pl/~jms/qnx/help/watcom/clibref/mq_overview.html
Post a Comment