Slight bug in MCAPI reference implementation's use of semget()

22 views
Skip to first unread message

EspeonEefi

unread,
Jun 4, 2010, 2:18:38 AM6/4/10
to Multicore Association, embarrassin...@mit.edu
I just wanted to report a slight bug in the use of semget() in the
file
mcapi/src/mcapi_trans/mcapi_trans_sm/transport_sm.c in the reference
implementation [1] of MCAPI.

[1] http://www.multicore-association.org/request_mcapi.php?what=MCEXP

According to the POSIX specification for semget() [2], semaphore
identifiers need only be non-negative, not necessarily positive. Thus,
0
is a perfectly legal semaphore identifier. Instead of using an
identifier of 0 to signal an error in semget(), semget() uses an
identifier of -1.

[2] http://www.opengroup.org/onlinepubs/9699919799/functions/semget.html

Unfortunately, the reference implementation assumes that a semaphore
identifier of 0 signals an error. We were trying to run the reference
implementation on a specialized system that nevertheless supported the
pthreads interface, and the reference implementation's mistreatment of
a
semaphore identifier of 0 was tripping us up.

The extremely hacky patch at the end of this email fixed things enough
for our uses, and I provide it here mainly for others who might be
looking for a quick fix for the same problem. However, if this is
going
to get fixed in the reference implementation, I would highly recommend
a
deeper exploration of the signedness of the return values of the
various
functions involved (the semaphore-handling functions in
mcapi/src/mcapi_trans/mcapi_trans_sm/mrapi/transport_sm_mrapi.c,
mrapi/src/mrapi.c, and mrapi/src/sysvr4/sysvr4.c), and how those
functions should signal to their callers error conditions.

Best,
Austin Chu
Student in 6.846 "Parallel Computing", spring 2010
Massachusetts Institute of Technology

Index: mcapi/src/mcapi_trans/mcapi_trans_sm/transport_sm.c
===================================================================
--- mcapi/src/mcapi_trans/mcapi_trans_sm/transport_sm.c (revision 281)
+++ mcapi/src/mcapi_trans/mcapi_trans_sm/transport_sm.c (revision 282)
@@ -178,7 +178,7 @@

/* public globals (visible to all) */
/* the semaphore id */
-uint32_t sem_id;
+uint32_t sem_id = UINT32_MAX;
/* the shared memory address */
void* shm_addr;
/* for signal handler */
@@ -259,10 +259,10 @@
int shmkey = 0;
mcapi_boolean_t rc = MCAPI_TRUE;

- if (!sem_id) {
+ if (sem_id == UINT32_MAX) {
/* create the semaphore (it may already exist) */
sem_id = transport_sm_create_semaphore(semkey);
- if (!sem_id) {
+ if (sem_id == UINT32_MAX) {
return MCAPI_FALSE;
}
}
Reply all
Reply to author
Forward
0 new messages