online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
package main import ( "fmt" "math/rand" "sync" "time" ) type Semaphore chan struct{} func NewSemaphore(capacity int) Semaphore { return make(Semaphore, capacity) } func (s Semaphore) Acquire() { s <- struct{}{} } func (s Semaphore) Release() { <-s } const ( partyCapacity = 5 totalGuests = 10 ) func guest(id int, partyRoom Semaphore, wg *sync.WaitGroup) { defer wg.Done() fmt.Printf("Guest %d is trying to enter the party room\n", id) partyRoom.Acquire() fmt.Printf("Guest %d has entered the party room\n", id) // Party for a random duration partyDuration := time.Duration(rand.Intn(3)+1) * time.Second time.Sleep(partyDuration) fmt.Printf("Guest %d is leaving the party room\n", id) partyRoom.Release() } func main() { partyRoom := NewSemaphore(partyCapacity) var wg sync.WaitGroup for i := 0; i < totalGuests; i++ { wg.Add(1) go guest(i, partyRoom, &wg) // Small delay to make output more readable time.Sleep(100 * time.Millisecond) } wg.Wait() fmt.Println("The party is over!") }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue