C++ :: Delete Object In Multi-thread Situation
Feb 11, 2014
I have to delete an object at a time that I don't know it's held by another thread(s) or not. For example
static void foo(CLASS* ref){
pthread_mutex_lock(&l);//[POINT-A]
//using ref
//do something thread safe
pthread_mutex_unlock(&l);
delete ref;// how can I find out there is no any thread held at [POINT-A]
}
View 2 Replies
ADVERTISEMENT
Sep 14, 2014
I delete rows in datagridview using chcekbox column. I write the following code:
private void btndelpay_Click(object sender, EventArgs e) {
DialogResult dr = MessageBox.Show("delete row", "do you want to delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dr == DialogResult.Yes)
[Code] ......
my problem is /how to umcheck from rows in datagridview in chechboxes column when the user select dialogResult.NO
View 1 Replies
View Related
Apr 18, 2014
int NextPixel(int antIndex, int currentPixel , Ant *ant , IplImage *edgeImg) {
int left = currentPixel - 1 ;
int right = currentPixel + 1 ;
int up = currentPixel - edgeImg->widthStep ;
int down = currentPixel + edgeImg->widthStep ;
[[Code] ....
if those lines are uncommented , program gives heap error.Why?
View 3 Replies
View Related
Nov 27, 2014
How to add/delete object dynamically run time ?? I have a question in which i need to add/delete object dynamically dynamically how to do it ??
View 2 Replies
View Related
Dec 14, 2014
I have this class I have been working with,
Code:
// objects to hold results, row id, and name
class result_holder {
public:
// initialize class members
result_holder() : row_id(0), row_value(0.0), row_name("") { }
[Code] ....
There are cases where I need to find an object based on the value of row_id and delete the object from the vector row_results. I could find the proper object by looping through the vector and testing against each member.
Code:
// id I am looking for
unsigned int id_to_delete = 12;
for(i=0; i<row_results.size(); i++) {
if(id_to_delete == row_results[i].row_id) {
delete row_results[i];
}
}
I have used find before to find the position in a vector with a specific value, but I don't know how to use find to locate a specific value for an object member.
Also, is delete what I need to get rid of the object or should I be using erase as in,
Code:
// id I am looking for
unsigned int id_to_delete = 12;
for(i=0; i<row_results.size(); i++) {
if(id_to_delete == row_results[i].row_id) {
row_results.erase(row_results.begin()+i);
}
}
View 4 Replies
View Related
Jul 30, 2014
I have a class which I wrote and one of its object is "SerialPort" .NET class. In my MainWindow I created instance of my class called "SerialPortComm", then I send through some functions of mine, commands to the Serial Port, and I receive answers through "DataReceived" event.
But when I trying to use Dispatcher.BeginInvoke to write my data I have received (successfully), nothing shows on the RichTextBox which I'm trying to write to.
What can caused that, and How I can make it works?
SerialPortComm.cs
public partial class SerialPortComm : UserControl {
public SerialPort mySerialPort = new SerialPort();
public void Open_Port(string comNumber, int baudRate) {
mySerialPort.PortName = comNumber;
mySerialPort.BaudRate = baudRate;
[Code] ....
View 7 Replies
View Related
Dec 9, 2014
I have to manage a Clinic. I need to delete a booking (for example, if John said he's coming on March 22nd at 15:30 but then he say he's not going to come, I have to delete that booking so another person can use it).
idSearched: the id of the person that is not going to come. I have a lot of specialties and each one has a list. So I ask for the speciality to delete the node (the node contains John's booking). If I don't find it, I return (-1). searchSpecByID return a pointer to the list where the speciality is. So head will point to the first node of the list. In nodeToDelete I have the node I want to delete.
The program detects OK when is the first in the list and when not, but it doesn't delete the node.
Code:
typedef struct bookingList{
tSpecialty specialty;
struct nodo* intro;
} tList;
[Code].....
View 7 Replies
View Related
Aug 25, 2014
Suppose multiple threads are are trying to insert into a STL Map, both are trying to insert with same key. As per my understanding it will not cause any issue till you invalidate the iterator. Here as per me it will not invalidate the iterator.
View 2 Replies
View Related
Mar 26, 2014
When i am entering single character instead of 'miz' then it is working great. But when i am using multi character like 'miz' it is showing error output. i did this program with c++ it is working but not working in c.When i am running this program it is showing {warning] multi character constant.
Code:
#include<stdio.h>
#include<string.h>
main()
{
char a;
printf("Please Enter your First Name: ");
scanf("%s",&a);
[Code]....
View 1 Replies
View Related
Nov 29, 2013
I have pseudo code for the minimax algorithm but i was wondering what i would need to add to make it work with many players (n players)?
score minimax(state s, int n)
if (n = 0 OR s is a terminal node) {
if win position for program
return +inf;
if loss position for prg
[Code] ....
View 3 Replies
View Related
Feb 15, 2013
i want to make a two-dimensional array that is consisted by objects but i dont want to initialize the objects when i make the array.. i just want to make an array that each of his "cells" has the size of an object.For example,
class Human{
int hm=5;
...
};
and now i want to make a two dimensional array that each "cell" has the size of an Human but not a Human itself.
View 2 Replies
View Related
Jul 29, 2014
So basically, I started out with each wizard == 1 winform, but then I found another way to do it by making the content of each wizard step a user control, then say, on initial deployment, it load usercontrol1, then when i click next, the panel hide usercontrol1 for usercontrol2 and so forth. Would it be feasible to create all usercontrols (all the wizard step) and add them in an array, then i can load them by index?
View 7 Replies
View Related
Feb 25, 2014
I am new to Path Finding so I just know BFS, DFS, Djisktra, and Basic A*
I've searched for a few multi agent pathfind paper here and there. But I can't seem to understand them..
I am path finding in a grid map, 4 ways neighbor movement
My map isn't so big it's 300 x 300 up to 400 x 400
Most of the map is open space, I would say that at worst case 4/5 of the map is open space.
And there is probably around 100 agents.
I've tried running BFS 100 times and it takes around 200ms on average
Changing BFS to A* which I am thinking right now will definitely cost lesser time
But are there better ways in doing this ? and also Does running Single Agent A* multiple times doesn't cause problem for other agent ? perhaps causes deadlocks ? ( Considering that the path that have been determine for agents before the current searched is considered blocked )
View 1 Replies
View Related
Jan 26, 2014
I recently wrote a perceptron that determines whether a point is above or below a line. I'm trying to write a multi-layered ANN so I can use it to solve more complicated problems than "is this point above/below this line?"
Here's my source code: [URL] ....
Considering that a A XOR B is simply (NOT A AND OR (A AND NOT , and both of those are linearly separable...
View 14 Replies
View Related
Nov 17, 2014
#include<iostream.h>
#include<conio.h>
main()
[Code]....
I tried to make the output look like this --> ENTER YOUR NAME:Victor Collin ENTER YOUR COURSE:BSComSci
but everytime I entered my name the course went to the next line.How to make the output in the same?
View 7 Replies
View Related
Oct 16, 2012
I made a C++ Wrapper on top of ODBC.
I got a Connection, and a Statement class.
The Connection class holds the Database Connection ODBC Handle.
The Statement class holds the Statement Handle, there can be multiple per Connection. It is made and destroyed each time a query must be done on the DB.
Now I'm just wondering.
I have a multithreaded application.
Is keeping one Connection for one DB enough for the whole application? Where the different threads will make Statements based on that one Connection.Or is it better to keep a Connection per thread?
View 3 Replies
View Related
Feb 20, 2013
Here's the line of code with the warning
Code: if((addressbook[3][num][4]=='-')&&(strlen(addressbook[3][num])=='10'))
Or what might be the possible causes of such a warning?
View 2 Replies
View Related
Jun 1, 2014
I want to have a multi user chat over TCP/IP. I already have the code for both the server and the client and so far I am able to send messages from the client to the server. Now I want to make it a multi user chat. I am executing the codes using Visual studio's Command prompt(not Windows Command Prompt). I have read somewhere that we have to use select() function.
View 2 Replies
View Related
Dec 9, 2013
this last few days I've been coding this one particular file
Hero.cpp
namespace Hero {
namespace {
// all data here
}
}
then the code grew a bit to about 700 line
Then now I want to implement hero skill system It needs the access to data inside the unnamed namespace where I put just about everything.. but it's unnamed namespace, it's only valid within one file and I should hide all that data from Hero interface in Hero.h How should I do this ?
View 12 Replies
View Related
Jan 29, 2015
I need to create subfunctions to do basic Matrix mathematics (addition, subtraction, etc.) I need to be able to pass bot of my Matrices to subfunctions. I started with the addition sub function and I cant get the code to run. I keep getting expected primary-expression before ']' token error for line 75.
#include <iostream>
#include <stdio.h>
using namespace std;
[Code].....
View 1 Replies
View Related
Jan 30, 2013
I have always written like a>='0'&&a<='9'&&a>='a'&&a<='z' in loops etc, but no more. Basically add whatever you want to condition, and if you want point a to point b just separate them with a '-' sign. Simply
while(!isCharInside(x,"|a-zA-Z0-9.*/=|-|")){/*code*/}
bool isCharInside(char check,string condition="a-zA-Z*/+=|-|0-9"){
for(unsigned int x=0,z=getLenght(condition);x<z;++x){
if(condition[x+1]=='-'&&(condition[x]!='|'&&condition[x+2]!='|')){
if(condition[x]>condition[x+2])swap(condition[x],condition[x+2]);
for(;condition[x]<=condition[x+2];++condition[x]){if(condition[x]==check)return true;};x+=2;}
else if(check==condition[x])return true;
}
return false;}
View 1 Replies
View Related
Apr 8, 2014
I am working on the game of fifteen.Yes this is home work. I was wondering if it is possible to save the indexes of an element in a two dim array. I need to find the position of the space in the two dim array save it, find the position of the tile which is passed in as an int and swap the two if they are adjacent. Here is my code
Edit: I can do this by saving i and j in separate int variables but is there a more elegant way of doing this
int board[MAX][MAX];
void init();
void swap(int* lhs, int* rhs);
[Code].....
View 3 Replies
View Related
Jul 15, 2014
I'm trying to union eleven tables to call out data. Parent table is 'Events', child tables are 'SR1Laptimes', 'SR2Laptimes' and so on (there are ten SR... tables). Primary key in all tables is EventName. Parent/Child relationship is Events.EventName/SR1Laptimes.EventName etc All tables that start with SR have the same Schema. I'm trying to call out MIN(Q1) across all table but first need to Union them I believe. Here is my code.
myCommand.CommandText = "SELECT MIN(Q1), MIN(Q2), MIN(Q3), MIN(Q4), MIN(LaptimesMinutes), MIN(LaptimesSeconds) FROM (SELECT * FROM Events UNION ALL SELECT * FROM SR1Laptimes UNION ALL SELECT * FROM SR2Laptimes) WHERE (Events.Track = @track) AND (Events.Number = @number) AND (Events.Rider = @rider)";
myCommand.Parameters.AddWithValue("@track", analysisTrackComboBox.Text);
myCommand.Parameters.AddWithValue("@number", analysisNumberComboBox.Text);
myCommand.Parameters.AddWithValue("@rider", analysisRiderComboBox.Text);
View 4 Replies
View Related
Oct 24, 2014
Here is the code,
Code:
void foo() {
Acquiring lock
do something...
Func();
Releasing Lock
}
If the function Func throws an exception, there is potential deadlock issue. Then I handle exception like this,
Code:
void foo() {
Acquiring lock
do something...
try{
Func();
[Code] ....
Is this a good practice? I wonder how I can apply RAII in handling exception here.
View 2 Replies
View Related
Jul 21, 2012
I have a compressor that takes a file and first compresses it to an intermediate file "temp.lz", before compressing it to the final format. Immediately after that the file be removed by calling c's remove(char*). The problem I am afraid of is if calling this compressor from different processes is safe because of the intermediate file created which has the same name for all. (say temp.lz). Will I have problems when callinga sytem call from different process something like: system ("compress -i test.txt -o test.z") ?
I was thinking of rewriting the compressor to avoid the use of the temporary file but that is a bit awkward. I just need to use a temporary stream (file) different for each process to avoid race conditions.
View 8 Replies
View Related
Apr 28, 2014
If I wanted an int connected to a float connected to a string connected to a POD, would all I have to do is :
Code:
template<class T, class X>
struct node {
T data;
node<X> *next;
};
Or would I be forced into using polymorphism?
View 10 Replies
View Related