thread join부분 Segmentation fault (core dumped) 문제...

jaewan0114@GitHub의 이미지

void check_sudoku(void)
{
int i, j;
pthread_t tid[11];
int tid_index = 0;

/*
* 검증하기 전에 먼저 스도쿠 퍼즐의 값을 출력한다.
*/
for (i = 0; i < 9; ++i)
{

for (j = 0; j < 9; ++j){

printf("%2d", sudoku[i][j]);
}
printf("\n");

}
printf("---\n");




/*
* 스레드를 생성하여 각 행을 검사하는 check_rows() 함수를 실행한다.
*/
// threadId 배열 선언
pthread_create (& tid [tid_index ++], NULL, check_rows, NULL);

// 여기를 완성하세요
/*
* 스레드를 생성하여 각 열을 검사하는 check_columns() 함수를 실행한다.
*/
// 여기를 완성하세
pthread_create (& tid [tid_index ++], NULL, check_columns, NULL);

/*
* 9개의 스레드를 생성하여 각 3x3 서브그리드를 검사하는 check_subgrid() 함수를 실행한다.
* 3x3 서브그리드의 위치를 식별할 수 있는 값을 함수의 인자로 넘긴다.
*/
// 여기를 완성하세요
pthread_create (&tid[tid_index++], NULL, check_subgrid, NULL);
/*
* 11개의 스레드가 종료할 때까지 기다린다.
*/
// 여기를 완성하세요
for (i = 0; i {
pthread_join(tid[i], NULL); // 스레드가 반환 될 때까지 기다립니다.
}

/* 각 행에 대한 검증 결과를 출력한다.
*/
printf("ROWS: ");
for (i = 0; i < 9; ++i)
printf(valid[0][i] == 1 ? "(%d,YES)" : "(%d,NO)", i);
printf("\n");
/*
* 각 열에 대한 검증 결과를 출력한다.
*/
printf("COLS: ");
for (i = 0; i < 9; ++i)
printf(valid[1][i] == 1 ? "(%d,YES)" : "(%d,NO)", i);
printf("\n");
/*
* 각 3x3 서브그리드에 대한 검증 결과를 출력한다.
*/
printf("GRID: ");
for (i = 0; i < 9; ++i)
printf(valid[2][i] == 1 ? "(%d,YES)" : "(%d,NO)", i);
printf("\n---\n");

}

계속 Segmentation fault (core dumped) 오류가 발생하는데 찾아보니까 join부분이 문제인거 같더라고요....도대체 어떻게 해야 오류가 사라질까요...

chanik의 이미지

스레드를 11개 만든다고 주석을 달았지만 3개밖에 안 만들고 있네요.
그리고 코드가 듬성듬성 빠진채로 올라온 것 같습니다.
아래와 같이 code 태그로 감싸서 깨끗하게 다시 올리시면 답글이 좀 더 잘 달릴겁니다.

<code lang="c">
if ( a != b ) {
    printf ("different a and b\n);
}
</code>

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.