As I understand, it will execute in parallel by default. There's a pool of threads for running goroutines, defaulting initially to the number of cores. If a syscall blocks, then other threads will continue to run - and (I think) an extra thread is started too.
> But still I had to use sync.WaitGroup to actually make the main go-routine wait before this file write happens. Doesn't that prove that the main goroutine and the file write/flush goroutine are taking place in parallel? On Wednesday, 15 June 2022 at 18:10:01 UTC+2 abeshek.ram...@gmail.com wrote: > Hi, > I'm trying to make a key-value store like LevelDB from scratch for > learning about database internals. I got stuck in a place where I need to > flush some data to disk file parallely while the main thread is executing > reads and writes. I tried writing it as a go-routine but as I understand > it, the go-routine (for flushing data to disk) starts executing but blocks > at file write and switches back to main go-routine. > > When I tried to print how many cores go runtime was using with > runtime.NumCPU(), I got 12 as the result. But still I had to use > sync.WaitGroup to actually make the main go-routine wait before this file > write happens. > > I'm relatively new to writing concurrent programs in Go. Is there any way > to make it execute paralley? > > Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/a54e7515-b253-4232-b6dc-e14d4b28fe31n%40googlegroups.com.