我想以某種方式使用pthread庫中的讀寫鎖,即作者優先於讀者。我在我的男人頁讀取Pthread - 設置調度程序參數
如果線程執行調度選項的支持,並參與了鎖的線程與調度策略的SCHED_FIFO或SCHED_RR執行,則調用線程不應獲得,如果一個作家鎖持有該鎖或者如果具有較高或相同優先級的寫入者被鎖定在鎖上;否則,調用線程將獲得該鎖。
所以我寫的小功能,設置了線程調度選項。
void thread_set_up(int _thread)
{
struct sched_param *_param=malloc(sizeof (struct sched_param));
int *c=malloc(sizeof(int));
*c=sched_get_priority_min(SCHED_FIFO)+1;
_param->__sched_priority=*c;
long *a=malloc(sizeof(long));
*a=syscall(SYS_gettid);
int *b=malloc(sizeof(int));
*b=SCHED_FIFO;
if (pthread_setschedparam(*a,*b,_param) == -1)
{
//depending on which thread calls this functions, few thing can happen
if (_thread == MAIN_THREAD)
client_cleanup();
else if (_thread==ACCEPT_THREAD)
{
pthread_kill(params.main_thread_id,SIGINT);
pthread_exit(NULL);
}
}
}
對不起那些a,b,c
但我試圖malloc
一切,我仍然可以在電話會議中pthread_setschedparam
SIGSEGV
,我想知道爲什麼嗎?
1. pthread_kill是通知主線程,另一個遇到致命錯誤,我忽略sigint執行清理的信號處理程序 – Andna
2.你是正確的關於系統調用和pthread_self,我改變了傳遞參數到pthread_self,它的工作3.also你就在這裏。我非常感謝你的幫助。 – Andna