[질문] DB 질의시 락이 걸렸습니다.

leolo의 이미지

아래의 코드는 handler 쓰레드 여러개, receiver 쓰레드 한개를 띄우는 예제입니다.
receiver는 하나로, 데이터를 받어서 큐에 넣습니다.
handler는 여러개로 쓰레드 각각 connection을 만듭니다.
문제는 thread id가 pid[0]인 쓰레드가 데이터를 큐에서 팝하고 DB를 질의했습니다. 여기서, 락이 걸렀습니다.

그렇다고 해서, 다른 데이터가 큐에 들어오는 것은 처리되지 않나요. 쓰레드는 pid[1], pid[2] 등 여러개가 있잖아요.
저는 지금 DB에 락 걸리는 상황이 발생되지 않아 그냥. pid[0] 쓰레드가 sleep(100) 되도록하고 다음 데이터를 보내봤습니다.

질문은 이겁니다.
DB 질의하는 쓰레드가 총 3개가 돌고 있습니다. 이중 한개가 질의하다가 락(임의로 sleep(100)을 주었습니다)이 걸렸습니다. 나머저 2개는 정상적으로 돌아야하는데, 돌지 않습니다. 여기서 정상적으로 돌지 않는다는 말은 첫번쨰 쓰레드가 락이 걸렸으면(sleep) 다른 쓰레드가 큐에서 팝해서 처리해야 하는데, 락 걸린 놈이 큐에서 팝을 합니다. 이게 말이 되는지요..
어떻게 하면 되는지요.

    pthread_t pid[MAX_PTHREAD_NUMBER];

    for(j = 0; j < g_info.config.dbthread; j++)
    {
        threadid = i;
        if(pthread_create(&pid[i++], NULL, (void *)handler, (void *)&threadid) != 0)
        {
            DebugLog((DEB_ERROR, "[%s.%d] handler thread create failed. \n", __FILE__, __LINE__));
            return K_FAIL;
        }

    }

    if(pthread_create(&pid[i++], NULL, (void *)receiver, NULL) != 0)
    {
        DebugLog((DEB_ERROR, "[%s.%d] handler thread create failed. \n", __FILE__, __LINE__));
        return K_FAIL;
    }

    threadcnt = i;
    for(i = 0; i < threadcnt; i++)
    {
        pthread_join(pid[i], NULL);
    }

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.