C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2009, 02:43 PM
jaydstein jaydstein is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 3 jaydstein User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 7 m 40 sec
Reputation Power: 0
Structs and Segmentation Faults.

I'm trying to build a basic singly linkedlist implementation whose nodes are 'futures'. I need to store a reference to the head node in my thread_pool struct. When I try to store a reference to the node in thread_pool, I get a segmentation fault. The fault occurs in main() at the bottom of the code. Any ideas?

Code:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include "threadpool.h"

//forward declarations
struct thread_pool;
struct future;
struct future *list_create(int val);
void *thread_helper(void *arg);

//stores list of futures
struct thread_pool {
	struct future *list;
};

//stores pointer to method call
struct future { 
	thread_pool_callable_func_t data;
	int val;
	struct future *next;
};

//create a list
struct future *list_create(int val) {
	struct future *node;
	if(!(node=malloc(sizeof(struct future)))) return NULL;
	node->val=val;
	node->next=NULL;
	node->data=NULL;

	return node;	
}

int main() {
	struct thread_pool *threadpool;

        /* segmentation fault occurs at threadpool->list assignment */
	threadpool->list = list_create(1);

	return 0;
}


Thanks.
Justin

Reply With Quote
  #2  
Old November 12th, 2009, 02:52 PM
IOI-RLZ's Avatar
IOI-RLZ IOI-RLZ is offline
BANDITS 6'0 Clock !
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2006
Location: at the top of the stairway to heaven.
Posts: 729 IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)IOI-RLZ User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 7098 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 3 Days 19 m 25 sec
Reputation Power: 231
Send a message via MSN to IOI-RLZ Send a message via Yahoo to IOI-RLZ
Facebook
when you use threadpool what do you think it points to? Remember before you use a pointer you should know where or what it points to!
__________________
The only Verdict is Vengeance a Vendetta held as a Votive, not in Vain, for the Value and Veracity of such shall one day Vindicate the Vigilant and the Virtuous


Mav RLZ AC/DC RLZ

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Structs and Segmentation Faults.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap