Debian Codegraph @

examples/concurrent_create/concurrent_create.go

raw symbols SCIP
1 // Copyright © 2013, 2014, The Go-LXC Authors. All rights reserved.
2 // Use of this source code is governed by a LGPLv2.1
3 // license that can be found in the LICENSE file.
4
5 //go:build linux && cgo
6 // +build linux,cgo
7
8 package main
9
10 import (
11 "flag"
12 "log"
13 "runtime"
14 "strconv"
15 "sync"
16
17 "github.com/lxc/go-lxc"
18 )
19
20 var (
21 lxcpath string
22 count int
23 )
24
25 func init() {
26 runtime.GOMAXPROCS(runtime.NumCPU())
27 flag.StringVar(&lxcpath, "lxcpath", lxc.DefaultConfigPath(), "Use specified container path")
28 flag.IntVar(&count, "count", 10, "Number of containers")
29 flag.Parse()
30 }
31
32 func main() {
33 var wg sync.WaitGroup
34
35 options := lxc.BusyboxTemplateOptions
36 for i := 0; i < count; i++ {
37 wg.Add(1)
38 go func(i int) {
39 c, err := lxc.NewContainer(strconv.Itoa(i), lxcpath)
40 if err != nil {
41 log.Fatalf("ERROR: %s\n", err.Error())
42 }
43 defer c.Release()
44
45 log.Printf("Creating the container (%d)...\n", i)
46 if err := c.Create(options); err != nil {
47 log.Fatalf("ERROR: %s\n", err.Error())
48 }
49 wg.Done()
50 }(i)
51 }
52 wg.Wait()
53 }