// allocateTID returns an unused ThreadID from ns.
//
// Preconditions: ns.owner.mu must be locked for writing.
allocateTID returns an unused ThreadID from ns.

ns.owner.mu must be locked for writing.
// allocateTID returns an unused ThreadID from ns . // // Preconditions : ns . owner . mu must be locked for writing .
func (ns *PIDNamespace) allocateTID() (ThreadID, error) {
	if ns.exiting {
		return 0, syserror.ENOMEM
	}
	tid := ns.last
	for {
		tid++
		if tid > TasksLimit {
			tid = InitTID + 1
		}
		tidInUse := func() bool {
			if _, ok := ns.tasks[tid]; ok {
				return true
			}
			if _, ok := ns.processGroups[ProcessGroupID(tid)]; ok {
				return true
			}
			if _, ok := ns.sessions[SessionID(tid)]; ok {
				return true
			}
			return false
		}()
		if !tidInUse {
			ns.last = tid
			return tid, nil
		}
		if tid == ns.last {
			return 0, syserror.EAGAIN
		}
	}
}
func ( ns * PIDNamespace ) allocateTID ( ) ( ThreadID , error ) { if ns . exiting { return 0 , syserror . ENOMEM } tid := ns . last for { tid ++ if tid > TasksLimit { tid = InitTID + 1 } tidInUse := func ( ) bool { if _ , ok := ns . tasks [ tid ] ; ok { return true } if _ , ok := ns . processGroups [ ProcessGroupID ( tid ) ] ; ok { return true } if _ , ok := ns . sessions [ SessionID ( tid ) ] ; ok { return true } return false } ( ) if ! tidInUse { ns . last = tid return tid , nil } if tid == ns . last { return 0 , syserror . EAGAIN } } }
allocateTID returns an unused ThreadID from ns.
allocateTID returns an unused ThreadID from ns .
// "In this case, a subsequent fork(2) into this PID namespace will // fail with the error ENOMEM; it is not possible to create a new // processes [sic] in a PID namespace whose init process has // terminated." - pid_namespaces(7) // Next. // Is it available? // Did we do a full cycle? // No tid available.