>
> 2. What does “concurrent and blocking” mean for a data structure?


I think this means they’re asking about a form of concurrent programming 
where a caller will stop executing (block) while the data structure is 
accessed by a concurrent path. Non-blocking means the caller can continue 
without the access completing.

Concurrent means multiple code paths (either interwoven on one processor 
core or happening parallel on multiple cores) can read or write a shared 
data structure at the same time without data corruption. A key point to 
this explanation is that the data is in one computer memory that is shared 
between the code paths, but concurrency may also apply in different ways to 
programs designed for networks of computers (distributed computing) or 
other kinds of computer/OS architectures.

The approach I know for “concurrent and blocking” is the mutex 
(https://golang.org/pkg/sync/#RWMutex). This approach is prone to deadlocks 
in some cases.

There’s formal definitions in the study of concurrency that I avoided, the 
concept has been written about since the 1960s. See 
https://en.wikipedia.org/wiki/Mutual_exclusion for a Wikipedia starting 
point.

3. What does accessing one var from concurrent goroutines look like?


Having a mutex is one way, either as a separate var or as part of the 
struct type, where a data interaction locks the mutex before accessing the 
data structure and unlocks it when done. With the Go sync.RWMutex any 
number of goroutines can read from a data structure concurrently, but if a 
write is happening then RLock will wait until the write completes (Unlock) 
before continuing (and Lock will wait for all RUnlock and Unlock to happen 
before continuing).

Another is to use channels. These block while waiting to be read, or they 
can be buffered, so they could be part of a blocking or non-blocking 
concurrent data structure. I’ll probably explore this approach in the 
future since it doesn’t require a standard library dependency like the 
mutex does.

Matt

On Monday, April 9, 2018 at 12:03:10 PM UTC-5, Robert Solomon wrote:
>
> I would like to know the answers to 2 and 3 
>
> I'm a relatively new gopher 
>
> On Mon, Apr 9, 2018, 12:59 PM Robert Solomon <drro...@gmail.com 
> <javascript:>> wrote:
>
>> I would like to know the answers to 2 and 3
>>
>> I'm a relatively new gopher 
>>
>>>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to