Click here to Skip to main content
13,795,145 members

C / C++ / MFC

 
AnswerRe: CAsynSocket Client Question Pin
Richard Andrew x6423-Sep-18 6:37
professionalRichard Andrew x6423-Sep-18 6:37 
GeneralRe: CAsynSocket Client Question Pin
ForNow23-Sep-18 6:43
memberForNow23-Sep-18 6:43 
AnswerRe: CAsynSocket Client Question Pin
Victor Nijegorodov23-Sep-18 9:23
memberVictor Nijegorodov23-Sep-18 9:23 
QuestionC Programming Pin
Member 1399372921-Sep-18 23:29
memberMember 1399372921-Sep-18 23:29 
AnswerRe: C Programming Pin
Victor Nijegorodov22-Sep-18 0:35
memberVictor Nijegorodov22-Sep-18 0:35 
AnswerRe: C Programming Pin
CPallini23-Sep-18 22:44
mvpCPallini23-Sep-18 22:44 
GeneralMessage Closed Pin
24-Sep-18 8:31
memberStephen Wade24-Sep-18 8:31 
QuestionHow to deallocate memory allocated to a class instance Pin
meerokh21-Sep-18 6:58
membermeerokh21-Sep-18 6:58 
In constructor of my class WorkPackage, I am allocating a stack to each instance of workpackage and adding it to a queue. When a workpackage gets executed, the allocated stack get released in class destructor. The problem is that my destructor gets called before the execution of workpackage and program crashes with segmentation fault. I looked it up and thought that it is because of when i get the package from the queue:

PackageQueue.cpp
WorkPackage PackageQueue::GetWorkPackage(){
	if (isEmpty())
	    {
		return WorkPackage(); // return an empty work package
	    }
		pthread_mutex_lock(&getlock);
		WorkPackage data=WorkPackageQueue[front];
	    if (front == rear)
	    {
	        rear = -1;
	        front = -1;
	    }

	    else if (front == 0)
	        front = size-1;
	    else
	        front--;
	     pthread_mutex_unlock(&getlock);
	     return WorkPackage(data);
	}


I created a copy contructor to allocate a new stack to the instance in case of deletion after GetWorkPackage function

WorkPackage::WorkPackage(const WorkPackage& rhs){
	Wp_localstack.local_stack= Stack::make_stack();
	m_action=rhs.m_action;
	m_arguments=rhs.m_arguments;
}


But the problem is still there..Need hints to how can i do this correctly. I will provide more code if needed

modified 21-Sep-18 12:07pm.

AnswerRe: How to deallocate memory allocated to a class instance Pin
Victor Nijegorodov21-Sep-18 9:30
memberVictor Nijegorodov21-Sep-18 9:30 
GeneralRe: How to deallocate memory allocated to a class instance Pin
meerokh21-Sep-18 12:27
membermeerokh21-Sep-18 12:27 
AnswerRe: How to deallocate memory allocated to a class instance Pin
Richard MacCutchan21-Sep-18 22:35
protectorRichard MacCutchan21-Sep-18 22:35 
AnswerRe: How to deallocate memory allocated to a class instance Pin
«_Superman_»23-Sep-18 23:16
professional«_Superman_»23-Sep-18 23:16 
GeneralRe: How to deallocate memory allocated to a class instance Pin
meerokh26-Sep-18 2:45
membermeerokh26-Sep-18 2:45 
QuestionMessage Closed Pin
21-Sep-18 2:39
memberyaseen ramzan21-Sep-18 2:39 
AnswerRe: What are Destructors in Object-Oriented Programming Pin
David Crow21-Sep-18 3:39
memberDavid Crow21-Sep-18 3:39 
GeneralMessage Closed Pin
17-Sep-18 1:47
memberMember 1398713317-Sep-18 1:47 
QuestionWant to learn C. Newbie. Where to start? Pin
Quickbeam121316-Sep-18 20:40
memberQuickbeam121316-Sep-18 20:40 
AnswerRe: Want to learn C. Newbie. Where to start? Pin
Richard MacCutchan16-Sep-18 23:01
protectorRichard MacCutchan16-Sep-18 23:01 
GeneralRe: Want to learn C. Newbie. Where to start? Pin
Quickbeam121316-Sep-18 23:14
memberQuickbeam121316-Sep-18 23:14 
GeneralRe: Want to learn C. Newbie. Where to start? Pin
Richard MacCutchan17-Sep-18 0:00
protectorRichard MacCutchan17-Sep-18 0:00 
GeneralRe: Want to learn C. Newbie. Where to start? Pin
Quickbeam121317-Sep-18 6:23
memberQuickbeam121317-Sep-18 6:23 
AnswerRe: Want to learn C. Newbie. Where to start? Pin
leon de boer17-Sep-18 2:42
memberleon de boer17-Sep-18 2:42 
AnswerRe: Want to learn C. Newbie. Where to start? Pin
CPallini17-Sep-18 6:27
mvpCPallini17-Sep-18 6:27 
GeneralRe: Want to learn C. Newbie. Where to start? Pin
leon de boer17-Sep-18 6:34
memberleon de boer17-Sep-18 6:34 
GeneralRe: Want to learn C. Newbie. Where to start? Pin
CPallini17-Sep-18 6:56
mvpCPallini17-Sep-18 6:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.181207.3 | Last Updated 11 Dec 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid