1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package main
- import (
- "fmt"
- "os"
- "os/exec"
- "sync"
- )
- const (
- SYSCALL_NUMS = 400
- )
- func run(i int) {
- os.Setenv("DISABLE_SYSCALL", fmt.Sprintf("%d", i))
- _, err := exec.Command("node", "test.js").Output()
- if err != nil {
- fmt.Println(i)
- }
- }
- func main() {
- os.Chdir(".node_temp")
- // generate task list
- list := make([]int, SYSCALL_NUMS)
- for i := 0; i < SYSCALL_NUMS; i++ {
- list[i] = i
- }
- lock := sync.Mutex{}
- wg := sync.WaitGroup{}
- i := 0
- // run 4 tasks concurrently
- for j := 0; j < 4; j++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
- for {
- lock.Lock()
- if i >= len(list) {
- lock.Unlock()
- return
- }
- task := list[i]
- i++
- lock.Unlock()
- run(task)
- }
- }()
- }
- // wait for all tasks to finish
- wg.Wait()
- }
|