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 func newosproc(mp *m) {
22 if false {
23 print("newosproc m=", mp, " g=", mp.g0, " id=", mp.id, " ostk=", &mp, "\n")
24 }
25
26
27 var attr pthreadattr
28 if err := pthread_attr_init(&attr); err != 0 {
29 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
30 exit(1)
31 }
32
33
34 var stacksize uintptr
35 if pthread_attr_getstacksize(&attr, &stacksize) != 0 {
36 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
37 exit(1)
38 }
39 mp.g0.stack.hi = stacksize
40
41
42 if pthread_attr_setdetachstate(&attr, _PTHREAD_CREATE_DETACHED) != 0 {
43 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
44 exit(1)
45 }
46
47
48
49 var oset sigset
50 sigprocmask(_SIG_SETMASK, &sigset_all, &oset)
51 err := pthread_create(&attr, abi.FuncPCABI0(mstart_stub), unsafe.Pointer(mp))
52 sigprocmask(_SIG_SETMASK, &oset, nil)
53 if err != 0 {
54 write(2, unsafe.Pointer(&failThreadCreate[0]), int32(len(failThreadCreate)))
55 exit(1)
56 }
57
58 pthread_attr_destroy(&attr)
59 }
60
View as plain text