Source file
src/runtime/os_openbsd_libc.go
1
2
3
4
5
6
7 package runtime
8
9 import (
10 "internal/abi"
11 "unsafe"
12 )
13
14 var failThreadCreate = []byte("runtime: failed to create new OS thread\n")
15
16
17 func mstart_stub()
18
19
20
21
22 func newosproc(mp *m) {
23 if false {
24 print("newosproc m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
25 }
26
27
28 var attr pthreadattr
29 if err := pthread_attr_init(&attr); err != 0 {
30 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
31 exit(1)
32 }
33
34
35 var stacksize uintptr
36 if pthread_attr_getstacksize(&attr, &stacksize) != 0 {
37 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
38 exit(1)
39 }
40 mp.g0.stack.hi = stacksize
41
42
43 if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
44 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
45 exit(1)
46 }
47
48
49
50 var oset sigset
51 sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
52 err := pthread_create(&attr, abi.FuncPCABI0(mstart_stub), unsafe.Pointer(mp))
53 sigprocmask(_SIG_SETMASK, &oset, nil)
54 if err != 0 {
55 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
56 exit(1)
57 }
58
59 pthread_attr_destroy(&attr)
60 }
61
View as plain text