我正在使用named_semaphore
,我想声明一个信号量,然后询问它的进程数,但目前我得到这个例如:
const unsigned N_CORES = boost::thread::hardware_concurrency();
named_semaphore SEMAPHORE(open_or_create, PROCESS_NAME, N_CORES);
我首先要声明 SEMAPHORE,然后再获取内核数。
根据api:
//!Creates a global semaphore with a name, and an initial count.
//!If the semaphore can't be created throws interprocess_exception
named_semaphore(create_only_t, const char *name, unsigned int initialCount);
//!Opens or creates a global semaphore with a name, and an initial count.
//!If the semaphore is created, this call is equivalent to
//!named_semaphore(create_only_t, ...)
//!If the semaphore is already created, this call is equivalent to
//!named_semaphore(open_only_t, ... )
//!and initialCount is ignored.
named_semaphore(open_or_create_t, const char *name, unsigned int initialCount);
我试过了:
const unsigned N_CORES = boost::thread::hardware_concurrency();
named_semaphore SEMAPHORE(create_only, PROCESS_NAME, N_CORES);
// at other point
SEMAPHORE(open_or_create, PROCESS_NAME, numberOfCores);
但显示此错误:
term does not evaluate to a function taking 3 arguments