bounded buffer implementation


 
Thread Tools Search this Thread
Top Forums Programming bounded buffer implementation
# 15  
Old 11-14-2011
Yes , you are right but i am modifying the 'in' value as well, so it should work correctly right?
# 16  
Old 11-15-2011
no my friend,
it won't work as u expected. Try this
Code:
void *stage3(){
	
	int r;
	char file[] = "sample.txt";
	char *str;
	FILE *fd;
	fd = fopen(file,"r");
	
	while(1){
		
		r = random()%30000;
        usleep(r);
     
		sem_wait(&empty);
		pthread_mutex_lock(&mutex);
	
	    str=(char*)malloc(256*sizeof(char));
	    if(fgets(str,sizeof(str),fd)==NULL)
	    pthread_exit(NULL);
	    //printf("str = %s \n",str);
	         str[strlen(str)-1] = '\0';
	         buffer3[in] = str;
	         //printf("\n buffer3in[%d] = %s\n",in,buffer3[in]);
	         in = (in+1)%10;	           
	    pthread_mutex_unlock(&mutex);
	    sem_post(&full);		    	
	}
	printf("\n buffer3in[3] = %s\n",buffer3[3]);
	pthread_exit(NULL);
}

and don't forget to release the memory in stage4.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

XML text bounded with tag

Could you please give your inputs on the below issue: source.xml <?xml version="1.0" encoding="UTF-16"?> <P1 > <C1 type="i"><2></C1> <V1 type="string"><6.2></V1> <D1 type="string"> <D2><1.0></D2> <D2><2.0></D2> </D1> ...................... ...................... many more... (7 Replies)
Discussion started by: unme
7 Replies

2. Programming

C: CSV implementation

I have this code from a programming book: #include <stdio.h> #include <string.h> char buf; /* input line buffer */ char* field; /* fields */ char* unquote( char* ); /* csvgetline: read and parse line, return field count */ /* sample input:... (3 Replies)
Discussion started by: totoro125
3 Replies

3. Homework & Coursework Questions

Bounded Buffer is hanging, tried all I can. (C++)

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: My problem is that when creating my producers and consumers, if I don't create an equal number of both, the... (12 Replies)
Discussion started by: digitalbrainiac
12 Replies

4. UNIX for Advanced & Expert Users

Ipsec implementation

How can i implement Ipsec between two machines in linux_ ubuntu? any link?? suggestion?? (0 Replies)
Discussion started by: elinaz
0 Replies

5. UNIX for Dummies Questions & Answers

Lseek implementation

Hi everybody, i've been googling for ages now and gotten kinda desperate... The question, however, might be rather trivial for the experts: What is it exactly, i.e. physically, the POSIX function (for a file) "lseek" does? Does it trigger some kind of synchronization on disk? Is it just for the... (4 Replies)
Discussion started by: Humudituu
4 Replies

6. Linux

CAPWAP implementation

Hi I'm trying to implement CAPWAP protocol for my application.i'm able to configure my server side but i'm getting error at client(WTP) side as IOCTL error.while running the command #./WTP /mnt/cf/capwap/ : wlan2 Starting WTP... # WTP Loads... (0 Replies)
Discussion started by: ran789
0 Replies

7. UNIX for Advanced & Expert Users

Malloc Implementation in C

Hey Guys Some of my friends have got together and we are trying to write a basic kernel similar to Linux. I am trying to implement the malloc function in C and I am using a doubly linked list as the primary data structure. I need to allocate memory for this link list (duh...) and I don't feel... (2 Replies)
Discussion started by: rbansal2
2 Replies

8. Programming

Malloc implementation in C

Hey Guys I am trying to implement the malloc function for my OS class and I am having a little trouble with it. I would be really grateful if I could get some hints on this problem. So I am using a doubly-linked list as my data structure and I have to allocate memory for it (duh...). The... (1 Reply)
Discussion started by: Gambit_b
1 Replies

9. Shell Programming and Scripting

Need help on AWK implementation

Hi, I am accepting a string from user. compare this output with the awk output as below... echo "\n\n\tDay : \c" read day awk '{ if($day == $2) { if ($mon == $1) { print "Yes" }}}' syslog.txt I am getting the follwoing error awk: Field $() is not correct. The input line... (5 Replies)
Discussion started by: EmbedUX
5 Replies

10. Programming

Frame buffer implementation in Linux

At present, Iam working on Linux Framebuffer device console. I have a doubt sir. Please solve this. *How to display a string or a character in Frame buffer in C language? *What is the library file (is it <linux/fb.h> or other one?) used to do all I/O function manipulations like printing,... (0 Replies)
Discussion started by: chandra80
0 Replies
Login or Register to Ask a Question