what’s wrong with this? i already increased ulimit to 102400 etc. it’s not working?! something wrong with golang?
package main
/*
#include <pthread.h>
#include <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 main() {
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()
// Critical section: You can place code here that needs synchronization.
time.Sleep(300*time.Nanosecond)
C.unlock_mutex()
wg.Done()
}()
}
wg.Wait() // Wait for all goroutines to finish
log.Printf("same thing will crash in 3 second with more iterations")
time.Sleep(3*time.Second)
for i := 0; i < 1000000; i++ {
wg.Add(1)
go func() {
C.lock_mutex()
// Critical section: You can place code here that needs synchronization.
time.Sleep(300*time.Nanosecond)
C.unlock_mutex()
wg.Done()
}()
}
wg.Wait() // Wait for all goroutines to finish
}