what’s flawed with this? i already elevated ulimit to 102400 and so on. it’s not working?! one thing flawed with golang?
bundle primary
/*
#embody <pthread.h>
#embody <stdlib.h>
pthread_mutex_t lock;
void lock_init() {
pthread_mutex_init(&lock, NULL);
}
void lock_destroy() {
pthread_mutex_destroy(&lock);
}
void lock_mutex() {
pthread_mutex_lock(&lock);
}
void unlock_mutex() {
pthread_mutex_unlock(&lock);
}
*/
import "C"
import (
// "runtime"
"sync"
"log"
"time"
)
func primary() {
C.lock_init()
defer C.lock_destroy()
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
go func() {
C.lock_mutex()
// Crucial part: You may place code right here that wants synchronization.
time.Sleep(300*time.Nanosecond)
C.unlock_mutex()
wg.Achieved()
}()
}
wg.Wait() // Look ahead to all goroutines to complete
log.Printf("identical factor will crash in 3 second with extra iterations")
time.Sleep(3*time.Second)
for i := 0; i < 1000000; i++ {
wg.Add(1)
go func() {
C.lock_mutex()
// Crucial part: You may place code right here that wants synchronization.
time.Sleep(300*time.Nanosecond)
C.unlock_mutex()
wg.Achieved()
}()
}
wg.Wait() // Look ahead to all goroutines to complete
}
Why are you utilizing pthread_mutex_t
and never sync.Mutex
?
Only for demonstration objective?
pthread_create
could fail with EAGAIN for different causes than reaching max variety of processes. Reminiscence or stack house perhaps.
Different limits than ulimit -u
is perhaps related, for instance sysctl kernel.threads-max
or sysctl vm.max_map_count
Not that I learn the golang sources, however i can think about that goroutines should not scheduled on threads that maintain a pthread mutex. And so new threads are created till pthread_create
fails
Anyway, it appears to be a nasty thought to create 100k or extra pthreads. They aren’t as low cost as goroutines
@Helmut_Wais for inter-program golang international mutex locking. i set kernel threads-max to 1024000 however nonetheless crash at 80000 goroutines. learn how to resolve? did SetMaxThreads to 1024000 too, doesnt work. crash
How does that work?
Are you able to create extra threads in a C program utilizing pthread_create
?
no. do you’ve got any working resolution?