What kind of loop is for (;;)?

后端 未结 12 953
暖寄归人
暖寄归人 2021-01-04 04:42

Found in torvalds/linux-2.6.git -> kernel/mutex.c line 171

I have tried to find it on Google and such to no avail.

What does for (;;) instruct?<

相关标签:
12条回答
  • 2021-01-04 05:13

    The for(;;) is an infinite loop condition, similar to while(1) as most have already mentioned. You would more often see this, in kernel mutex codes, or mutex eg problem such as dining philosophers. Until the mutex variable is set to a particular value, such that a second process gets access to the resource, the second process keeps on looping, also known as busy wait. Access to a resource can be disk access, for which 2 process are competing to gain access using a mutex such that at a time only one process has the access to the resource.

    0 讨论(0)
  • 2021-01-04 05:13

    It's equivalent to while( true )

    Edit: Since there's been some debate sparked by my answer (good debate, mind you) it should be clarified that this is not entirely accurate for C programs not written to C99 and beyond wherein stdbool.h has set the value of true = 1.

    0 讨论(0)
  • 2021-01-04 05:15

    I means:

    #define EVER ;;
    
    for(EVER)
    {
         // do something
    }
    

    Warning: Using this in your code is highly discouraged.

    0 讨论(0)
  • 2021-01-04 05:16

    It's an infinite loop that you'll have to break somehow from within using a break, return or goto statement. or either some interrupt happens otherwise this loop will run infinitely and executes ;(null statement) every time

    0 讨论(0)
  • 2021-01-04 05:18

    it is an infinite for loop.

    0 讨论(0)
  • 2021-01-04 05:20

    That was obviously an infinite loop condition.

    0 讨论(0)
提交回复
热议问题