# Go Concurrency

> Concurrencia, goroutines y thread-safety en Go. Usar al diseñar código concurrente o manejar recursos compartidos. Use when this capability is needed.

- Skill: `tomevault-io/go-concurrency` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/go-concurrency`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/go-concurrency/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/go-concurrency

---


# Skill: go-concurrency

Concurrencia, goroutines y thread-safety en Go.

## Cuándo usar este skill

- Al diseñar código concurrente
- Al manejar recursos compartidos
- Al implementar caching thread-safe

## Mecanismos de Sincronización

### sync.Mutex

```go
type Registry struct {
    mu   sync.Mutex
    data map[string]Item
}

func (r *Registry) Set(key string, item Item) {
    r.mu.Lock()
    defer r.mu.Unlock()
    r.data[key] = item
}
```

### sync.RWMutex (lecturas frecuentes)

```go
func (c *Cache) Get(key string) (Item, bool) {
    c.mu.RLock()
    defer c.mu.RUnlock()
    item, ok := c.items[key]
    return item, ok
}
```

### sync/atomic (contadores)

```go
func (s *Stats) RecordHit() {
    atomic.AddUint64(&s.hits, 1)
}
```

### sync.Pool (reutilizar objetos)

```go
var bufPool = sync.Pool{
    New: func() interface{} { return new(bytes.Buffer) },
}
```

## Patrones con Context

```go
func (v *Validator) Validate(ctx context.Context, resource []byte) (*Result, error) {
    select {
    case <-ctx.Done():
        return nil, ctx.Err()
    default:
    }
    // continuar...
}
```

## Checklist

```markdown
- [ ] ¿Los recursos compartidos están protegidos?
- [ ] ¿Se usa RWMutex donde hay más lecturas?
- [ ] ¿Los goroutines tienen forma de terminar?
- [ ] ¿Se propaga context correctamente?
```

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/gofhir) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-13 -->

