2016-04-27 45 views
2

我有以下代碼:信號燈不斷崩潰的OS X

sem_t *semFull = sem_open("/semFull", O_CREAT, 0644, 0); 
sem_t *semEmpty = sem_open("/semEmpty", O_CREAT, 0644, shared.buffSize); 

這段代碼工作完全在Linux上,但是當我嘗試執行它在OS XI不斷收到分段錯誤

任何人都可以幫我解決這個問題?

感謝

回答

1

你不應該在OS X上使用sem_t,你應該使用semaphore_t

您需要輸入以下庫

#include <mach/semaphore.h> 
#include <mach/task.h> 
#include <mach/mach_init.h> 

,並且可以使用創建信號量:

semaphore_create(mach_task_self(), &shared.full, SYNC_POLICY_FIFO, 0); 
semaphore_create(mach_task_self(), &shared.empty, SYNC_POLICY_FIFO, shared.buffSize); 

你的問題應該採用這種方法來解決。

+0

感謝您的幫助!我會盡力實現你給我的代碼 –