日期:2014-05-16  浏览次数:20725 次

这么简单的sem_int竟然失败
/*testSemp文件内容如下*/
#include   <semaphore.h>

static   sem_t   semVal;
int   main()
{
          int   nVal;
          sem_init(&semVal,0,nVal);
          return   1;
}

g++   -o   testSemp   testSemp.cpp   //没有问题
./testSemp       //竟然报Bad   system   call(core   dumped)

我是在freebsd上跑的,哪位大哥碰到过?

------解决方案--------------------
ERRORS
The sem_init() function will fail if:
[EINVAL]
The value argument exceeds SEM_VALUE_MAX.
[ENOSPC]
A resource required to initialise the semaphore has been exhausted, or the limit on semaphores (SEM_NSEMS_MAX) has been reached.
[ENOSYS]
The function sem_init() is not supported by this implementation.
[EPERM]
The process lacks the appropriate privileges to initialise the semaphore.
------解决方案--------------------
是否是nVal 没有初始化阿, 你试试 int nVal=0; 看看
------解决方案--------------------
问题不清楚, 我手头没UNIX, 没法给你试试.