Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in simple producer/consumer program #14

Open
albertolluch opened this issue Nov 22, 2017 · 3 comments
Open

Crash in simple producer/consumer program #14

albertolluch opened this issue Nov 22, 2017 · 3 comments
Labels

Comments

@albertolluch
Copy link
Member

albertolluch commented Nov 22, 2017

The program below crashes:

// This is a simple producer/consumer system.

package main

import (
	"fmt"
	"math/rand"
	"time"

	. "github.com/pspaces/gospace"
)

// PRODUCERS defines the number of producers.
const PRODUCERS = 2

// NTASKS defines the number of tasks each producer generates.
const NTASKS = 2

// WORKERS defines the number of workers.
const WORKERS = 2

func main() {

	rand.Seed(time.Now().UTC().UnixNano())

	bag := NewSpace("bag")

	for i := 0; i < PRODUCERS; i++ {
		go producer(&bag, i, NTASKS)
	}

	for i := 0; i < WORKERS; i++ {
		go worker(&bag, i)
	}

	bag.Query("done")

}

func producer(bag *Space, me int, ntasks int) {
	for i := 0; i < ntasks; i++ {
		x := rand.Intn(10)
		bag.Put(x)
		fmt.Printf("Producer %d added %d to the bag...\n", me, x)
	}
}

func worker(bag *Space, me int) {
	var x int
	var y int
	for {
		// Get one number.
		bag.Get(&x)
		// Try to get another number.
		_, err := bag.GetP(&y)
		if err == nil {
			// If found then reduce.
			fmt.Printf("Worker %d got pair (%d,%d) to reduce.\n", me, x, y)
			x = x + y
			bag.Put(x)
			fmt.Printf("Worker %d added %d to the bag.\n", me, x)
		} else {
			// If not found, replace the first number.
			bag.Put(x)
		}
	}
}
@ghost
Copy link

ghost commented Nov 22, 2017

This is now fixed in commit 3258710 in the aggregation-policy branch.

@ghost ghost closed this as completed Nov 22, 2017
@ghost ghost self-assigned this Nov 22, 2017
@albertolluch
Copy link
Member Author

Is the branch stable or should I rather wait until the merge? This issue is not critical right now, so I can wait.

@albertolluch
Copy link
Member Author

I am reopening this. There is still a "concurrent map write" crash on my side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant