1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Multithreaded test program for debugger integration tests
package main
import (
"fmt"
"sync"
)
const numWorkers = 2
var sharedCounter int
var counterMutex sync.Mutex
func worker(id int, start chan bool, done *sync.WaitGroup) {
defer done.Done()
// BREAKPOINT_MARKER: thread_entry
<-start
// BREAKPOINT_MARKER: worker_start
counterMutex.Lock()
sharedCounter++
localCount := sharedCounter
counterMutex.Unlock()
fmt.Printf("Worker %d incremented counter to %d\n", id, localCount)
// BREAKPOINT_MARKER: worker_end
}
func main() {
// BREAKPOINT_MARKER: main_start
fmt.Printf("Starting %d workers\n", numWorkers)
// Go lacks pthread_barrier equivalent in stdlib; buffered channel provides
// deterministic start ordering without requiring all goroutines to synchronize.
// Workers proceed independently after receiving start signal (differs from C
// barrier which requires all threads to reach barrier before any proceed).
startChan := make(chan bool, numWorkers)
var wg sync.WaitGroup
// Spawn workers
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go worker(i, startChan, &wg)
}
// BREAKPOINT_MARKER: main_wait
// Signal all workers to start (deterministic execution)
for i := 0; i < numWorkers; i++ {
startChan <- true
}
wg.Wait()
fmt.Printf("Final counter value: %d\n", sharedCounter)
}