// assignTIDsLocked ensures that new task t is visible in all PID namespaces in
// which it should be visible.
//
// Preconditions: ts.mu must be locked for writing.
assignTIDsLocked ensures that new task t is visible in all PID namespaces in
which it should be visible.

ts.mu must be locked for writing.
// assignTIDsLocked ensures that new task t is visible in all PID namespaces in // which it should be visible . // // Preconditions : ts . mu must be locked for writing .
func (ts *TaskSet) assignTIDsLocked(t *Task) error {
	type allocatedTID struct {
		ns  *PIDNamespace
		tid ThreadID
	}
	var allocatedTIDs []allocatedTID
	for ns := t.tg.pidns; ns != nil; ns = ns.parent {
		tid, err := ns.allocateTID()
		if err != nil {
			for _, a := range allocatedTIDs {
				delete(a.ns.tasks, a.tid)
				delete(a.ns.tids, t)
				if t.tg.leader == nil {
					delete(a.ns.tgids, t.tg)
				}
			}
			return err
		}
		ns.tasks[tid] = t
		ns.tids[t] = tid
		if t.tg.leader == nil {
			ns.tgids[t.tg] = tid
		}
		allocatedTIDs = append(allocatedTIDs, allocatedTID{ns, tid})
	}
	return nil
}
func ( ts * TaskSet ) assignTIDsLocked ( t * Task ) error { type allocatedTID struct { ns * PIDNamespace tid ThreadID } var allocatedTIDs [ ] allocatedTID for ns := t . tg . pidns ; ns != nil ; ns = ns . parent { tid , err := ns . allocateTID ( ) if err != nil { for _ , a := range allocatedTIDs { delete ( a . ns . tasks , a . tid ) delete ( a . ns . tids , t ) if t . tg . leader == nil { delete ( a . ns . tgids , t . tg ) } } return err } ns . tasks [ tid ] = t ns . tids [ t ] = tid if t . tg . leader == nil { ns . tgids [ t . tg ] = tid } allocatedTIDs = append ( allocatedTIDs , allocatedTID { ns , tid } ) } return nil }
assignTIDsLocked ensures that new task t is visible in all PID namespaces in
which it should be visible.
assignTIDsLocked ensures that new task t is visible in all PID namespaces in which it should be visible .
// Failure. Remove the tids we already allocated in descendant // namespaces. // New thread group.