Skip to content
Snippets Groups Projects
Commit a2e67fc8 authored by Tong Zhang's avatar Tong Zhang
Browse files

debug

parent 3a9fad79
Branches debug
No related tags found
No related merge requests found
#include <random> #include <random>
//using namespace std;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
std::random_device generator; std::random_device generator;
...@@ -8,7 +8,11 @@ int main(int argc, char **argv) ...@@ -8,7 +8,11 @@ int main(int argc, char **argv)
for (int i=0; i<1024; i++) { for (int i=0; i<1024; i++) {
int nom = intdist(generator); int nom = intdist(generator);
int denom = intdist(generator); int denom = intdist(generator);
while(denom == 0)
{
denom = intdist(generator);
}
res[i] = nom / denom; res[i] = nom / denom;
} }
return 0; return 0;
......
File added
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#define BUFFSIZE 1024
using namespace std;
int main(int argc, char **argv)
{
int ret = 0;
char *buff;
// Fix num lines, num columns, strdup-1
FILE *fin = fopen("bible.txt", "r");
FILE *fout = fopen("copy.txt", "w");
buff = (char*)malloc(BUFFSIZE);
if (NULL == buff)
{
fprintf(stderr, "molloc failed\n");
}
while (!feof(fin)) {
ret = fread(buff, 1, BUFFSIZE, fin);
if (ret != BUFFSIZE)
{
fwrite(buff, ret, 1, fout);
}
else
{
fwrite(buff, BUFFSIZE, 1, fout);
}
}
fclose(fin);
fclose(fout);
free(buff);
return 0;
}
namespace std {
static void getline(char *line, FILE *fin)
{
int c = '\0', cur = 0;
while (c != '\n' && (c = fgetc(fin)) != EOF) {
line[cur++] = c;
}
line[cur] = '\0';
}
}
using namespace std;
int main(int argc, char **argv)
{
int cur = 0;
char *lines[16536];
char line[80];
// Fix num lines, num columns, strdup-1
FILE *fin = fopen("bible.txt", "r");
while (!feof(fin)) {
getline(line, fin);
lines[cur] = (char*) malloc(strlen(line));
strcpy(lines[cur], line);
cur++;
}
fclose(fin);
FILE *fout = fopen("copy.txt", "w");
for (int i=0; i<cur; i++) {
fputs(lines[i], fout);
}
fclose(fout);
return 0;
}
File added
File added
$2 = 0
Starting program: C:\Users\54550\Desktop\Courses Resouces\Software design and constraction\Lab\Lab5\lab5-metaprogramming-and-debugging-lab-master\debugging\dividearrays.exe
[New Thread 9152.0x75d0]
[New Thread 9152.0x7538]
[New Thread 9152.0x8378]
[New Thread 9152.0xbe8]
Thread 1 received signal SIGFPE, Arithmetic exception.
0x000000000040164b in main (argc=1, argv=0xe74510) at dividearrays.cpp:12
12 res[i] = nom / denom;
$3 = 0
File added
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
ptread_mutex_t mut;
int flag = 0;
typedef struct workitem { typedef struct workitem {
void (*fn)(double *); void (*fn)(double *);
int current; int current;
...@@ -14,6 +16,15 @@ typedef struct workitem { ...@@ -14,6 +16,15 @@ typedef struct workitem {
static void* launchThread(void *in) static void* launchThread(void *in)
{ {
pthread_mutex_lock(&mut);
if(flag == 1){
pthread_mutex_unlock(&mut);
return NULL;
}
else{
flag = 1;
}
pthread_mutex_unlock(&mut);
int n; int n;
workitem *data = (workitem*) in; workitem *data = (workitem*) in;
volatile int started = 0; volatile int started = 0;
......
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment