#include <stdio.h>
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
typedef struct pr_struct{
int owner;
int burst_time;
struct pr_struct *next_prcmd;
} prcmd_t;
static prcmd_t *pr_head = NULL;
static prcmd_t *pr_tail = NULL;
static int pending_request = 0;
static pthread_mutex_t prmutex = PTHREAD_MUTEX_INITIALIZER;
int add_queue(prcmd_t *node)
{
pthread_mutex_lock(&prmutex);
//code
prcmd_t *curNode = pr_head;
if(pr_head == NULL) { pr_head = node; return;}
while(curNode->next_prcmd)
{
curNode->next_prcmd = (prcmd_t*)malloc(sizeof(prcmd_t));
curNode = curNode->next_prcmd;
}
curNode->next_prcmd = node;
//
pending_request++;
pthread_mutex_unlock(&prmutex);
return(0);
}
int main()
{
if (pr_head == NULL)
{
printf("List is empty!\n");
}
prcmd_t *pr1;
pr1->owner = 1;
pr1->burst_time = 10;
add_queue(pr1);
prcmd_t *curNode = pr_head;
while(curNode->next_prcmd)
{
printf("%i\n", curNode->owner);
curNode = curNode->next_prcmd;
}
}
這是我現在有...
int main()
{
prcmd_t *pr1;
pr1 = (prcmd_t*)malloc(sizeof(prcmd_t));
pr1->owner = 1;
pr1->burst_time = 10;
if (pr_head == NULL)
{
printf("List is empty!\n");
}
add_queue(pr1);
prcmd_t *curNode = pr_head;
printf("made it here 1\n");
while(curNode->next_prcmd)
{
printf("in the while loop\n");
printf("%i\n", curNode->owner);
curNode = curNode->next_prcmd;
}
}
輸出是: 列表是空的! 使它這裏1
你在哪裏得到段錯誤? – QuantumMechanic 2011-05-06 04:18:43
我不知道。當我運行主。獲取stdout中的seg錯誤。 – Pulseczar 2011-05-06 04:28:18
然後在調試器下運行它。或者啓用核心轉儲,當你獲得核心時,運行一個調試器並查看堆棧跟蹤。 – QuantumMechanic 2011-05-06 04:29:31