deadlocked code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Theadmin77
    New Member
    • Nov 2006
    • 19

    deadlocked code

    For some reason i am unable to compile or execute the following code ...look like a i have a deadlock or something like that ...

    Could anyone send me into the right direction ? Thanks !!
    This is the code:


    Code:
    int itemCount
    
    procedure producer() {
        while (true) {
            item = produceItem()
    
            if (itemCount == BUFFER_SIZE) {
                sleep()
            }
    
            putItemIntoBuffer(item)
            itemCount = itemCount + 1
            
            if (itemCount == 1) {
                wakeup(consumer)
            }
        }
    }
    
    procedure consumer() {
        while (true) {
    
            if (itemCount == 0) {
                sleep()
            }
            
            item = removeItemFromBuffer()
            itemCount = itemCount - 1
            
            if (itemCount == BUFFER_SIZE - 1) {
                wakeup(producer)
            }
            
            consumeItem(item)
        }
    }
    Last edited by Ganon11; Oct 31 '07, 02:37 PM. Reason: Please use the [CODE] tags provided.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by Theadmin77
    For some reason i am unable to compile or execute the following code ...look like a i have a deadlock or something like that ...

    Could anyone send me into the right direction ? Thanks !!
    This is the code:


    int itemCount

    procedure producer() {
    while (true) {
    item = produceItem()

    if (itemCount == BUFFER_SIZE) {
    sleep()
    }

    putItemIntoBuff er(item)
    itemCount = itemCount + 1

    if (itemCount == 1) {
    wakeup(consumer )
    }
    }
    }

    procedure consumer() {
    while (true) {

    if (itemCount == 0) {
    sleep()
    }

    item = removeItemFromB uffer()
    itemCount = itemCount - 1

    if (itemCount == BUFFER_SIZE - 1) {
    wakeup(producer )
    }

    consumeItem(ite m)
    }
    }

    Please use code tqags while posting ur code.
    U wint get a deadlock problem when compiling ur code.
    Why there are no semi colons(;) in the code.
    First tell me, whether ur code is compiling?


    Raghuram

    Comment

    • Theadmin77
      New Member
      • Nov 2006
      • 19

      #3
      No unfortunately my code does not compile .

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        So what errors are you getting?

        Comment

        • Ganon11
          Recognized Expert Specialist
          • Oct 2006
          • 3651

          #5
          Is this even C or C++? If it is, then you are missing semicolons everywhere. If not, then this is the wrong forum for this post.

          Comment

          Working...