max.seven.max | 17 Jun 2012 10:17
Picon

Single threaded app are locks and mutexes required?

I am porting nodejs app to go
Nodejs app runs on a single thread and there is no synchronization required
I can't understand how atomic Goroutines are ?
Can context be switched when I access map or only when I access os io or lock or channel ?
Can I avoid excessive Locking with go if app would be single threaded?

Thank you
Max

Rémy Oudompheng | 17 Jun 2012 16:34
Picon

Re: Single threaded app are locks and mutexes required?

On 2012/6/17  <max.seven.max@...> wrote:
> I am porting nodejs app to go
> Nodejs app runs on a single thread and there is no synchronization required
> I can't understand how atomic Goroutines are ?
> Can context be switched when I access map or only when I access os io or lock or channel ?
> Can I avoid excessive Locking with go if app would be single threaded?

A switch between goroutines may happen anytime you perform a memory
allocation (which includes some variable declarations, conversion to
interface types, the use of defer, and map insertions). I think stack
allocations can also go through the same path.

Rémy.

Brad Fitzpatrick | 17 Jun 2012 17:17
Favicon

Re: Single threaded app are locks and mutexes required?

If you're using net/http, each new HTTP request is in its own goroutine.  Whenever different goroutines access the same map, you need locks.  I wouldn't worry about the cost of using locks yet.  (it's basically free, relatively).  Just get it working first, then profile.

On Sun, Jun 17, 2012 at 1:17 AM, <max.seven.max-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
I am porting nodejs app to go
Nodejs app runs on a single thread and there is no synchronization required
I can't understand how atomic Goroutines are ?
Can context be switched when I access map or only when I access os io or lock or channel ?
Can I avoid excessive Locking with go if app would be single threaded?

Thank you
Max

Max | 17 Jun 2012 18:35
Picon

Re: Single threaded app are locks and mutexes required?

Thank You Brad and Rémy



On Sunday, June 17, 2012 6:17:49 PM UTC+3, Brad Fitzpatrick wrote:
If you're using net/http, each new HTTP request is in its own goroutine.  Whenever different goroutines access the same map, you need locks.  I wouldn't worry about the cost of using locks yet.  (it's basically free, relatively).  Just get it working first, then profile.

On Sun, Jun 17, 2012 at 1:17 AM, <> wrote:
I am porting nodejs app to go
Nodejs app runs on a single thread and there is no synchronization required
I can't understand how atomic Goroutines are ?
Can context be switched when I access map or only when I access os io or lock or channel ?
Can I avoid excessive Locking with go if app would be single threaded?

Thank you
Max


Gmane