Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(798)

Side by Side Diff: src/pkg/net/net.go

Issue 13038043: code review 13038043: net: limit number of concurrent cgo calls (Closed)
Patch Set: diff -r b3ee0be87a1c https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/lookup_windows.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 Package net provides a portable interface for network I/O, including 6 Package net provides a portable interface for network I/O, including
7 TCP/IP, UDP, domain name resolution, and Unix domain sockets. 7 TCP/IP, UDP, domain name resolution, and Unix domain sockets.
8 8
9 Although the package provides access to low-level networking 9 Although the package provides access to low-level networking
10 primitives, most clients will need only the basic interface provided 10 primitives, most clients will need only the basic interface provided
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 d.Unlock() 426 d.Unlock()
427 } 427 }
428 428
429 func (d *deadline) setTime(t time.Time) { 429 func (d *deadline) setTime(t time.Time) {
430 if t.IsZero() { 430 if t.IsZero() {
431 d.set(0) 431 d.set(0)
432 } else { 432 } else {
433 d.set(t.UnixNano()) 433 d.set(t.UnixNano())
434 } 434 }
435 } 435 }
436
437 // Limit the number of concurrent cgo-using goroutines, because
438 // each will block an entire operating system thread. The usual culprit
439 // is resolving many DNS names in separate goroutines but the DNS
440 // server is not responding. Then the many lookups each use a different
441 // thread, and the system or the program runs out of threads.
442
443 var threadLimit = make(chan struct{}, 500)
444
445 func acquireThread() {
446 threadLimit <- struct{}{}
447 }
448
449 func releaseThread() {
450 <-threadLimit
451 }
OLDNEW
« no previous file with comments | « src/pkg/net/lookup_windows.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b