[go-nuts] Re: Call of a Go-function inside C-code

2019-10-03 Thread dr . ch . maurer
Dear Ian Lance Taylor,

thankyou very much for your hint!

Kind regards, Christian

Am Mittwoch, 2. Oktober 2019 04:36:4D8 UTC+2 schrieb Christian Maurer:
>
> Dear community,
>
> what is wrong with the following simple code, which yields "undefined 
> reference for F" ?
>
>
> file f.go:
>
> package main
> // #include "f.h"
> // void f (int a) { F(a) }
> import "C"
>
> func F(a int) { println(a) }
> func main() { C.f(7) }
>
>
> file f.h:
>
> extern void F (int a);
>
> //export F
>
>
> Thanks in advance for any help,
> Christian
>

-- 
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/0b53181a-eb6c-4c0f-a1f9-df5013c0eb55%40googlegroups.com.


[go-nuts] Re: Call of a Go-function inside C-code

2019-10-03 Thread dr . ch . maurer
Dear Ian Lance Taylor,

thankyou very much for your hint!

Kind regards, Christian

-- 
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/969b21e9-7b90-4e39-bb63-2f9a6418d198%40googlegroups.com.


[go-nuts] Call of a Go-function inside C-code

2019-10-01 Thread dr . ch . maurer
Dear community,

what is wrong with the following simple code, which yields "undefined 
reference for F" ?


file f.go:

package main
// #include "f.h"
// void f (int a) { F(a) }
import "C"

func F(a int) { println(a) }
func main() { C.f(7) }


file f.h:

extern void F (int a);

//export F


Thanks in advance for any help,
Christian

-- 
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/e31defe4-fde3-47c5-b052-8979939257a2%40googlegroups.com.


[go-nuts] Re: mutual exclusion algorithm of Dijkstra - strange behaviour

2019-08-16 Thread dr . ch . maurer
Dear Community and dear Go-developers,

Meanwhile it is clear why things do not work:
The Go-Scheduler is unable to allow to switch to another goroutine in 
busy-waiting-loops -
the only possibility to get around that problem is either to put 
"switch-steps" into the source
- either "time.Sleep(1)" or "runtime.Gosched()".
I think that THIS SHOULD BE DOCUMENTED IN THE LANGUAGE SPECIFICATION !

(See my book on https://maurer-berlin.eu/nspbuch - in it's 4th edition 
things are mentioned.)

With kind regards,
Christian Maurer

Am Montag, 30. Oktober 2017 18:30:06 UTC+1 schrieb Christian Maurer:
>
> Dear Go-community,
>
> I noticed a very strange effect by translating the
> mutual exclusion algorithm of E. W. Dijkstra to Go.
> Reference:
>   Cooperating Sequential Processes. Technical Report EWD-123,
>   Technological University Eindhoven (1965)
>   http://www.cs.utexas.edu/users/EWD/ewd01xx/EWD123.PDF)
>
> Inserting or omitting code lines A and B resp.
> changes the behaviour of this program very severely:
>
> With line A and without line B:
>   mutual exclusion is not guaranteed,
> with line B and without line A:
>   lock does not terminate and
> with both lines:
>   the program works as it should.
>
> --- 8< 
> package main
>
> import (
>   "math/rand"
>   "time"
> )
>
> const N = 10 // number of goroutines involved
>
> var (
>   turn int
>   b, c = make([]int, N+1), make([]int, N+1)
>   n= uint(0)
>   inCS = make([]bool, N+1)
>   s= make([]string, N+1)
>   done = make(chan int)
> )
>
> func chk(i int) {
>   for j := 1; j <= N; j++ {
> if j != i && inCS[j] {
>   panic("oops")
> }
>   }
> }
>
> func lock(i int) {
>   b[i] = 0
> L:
>   if turn != i {
> c[i] = 1
> if b[turn] == 1 {
>   turn = i
>   goto L
> }
>   }
>   time.Sleep(1) // A
>   c[i] = 0
>   time.Sleep(1) // B
>   for j := 1; j <= N; j++ {
> if j != i && c[j] == 0 {
>   goto L
> }
>   }
>   inCS[i] = true
>   chk(i)
> }
>
> func unlock(i int) {
>   inCS[i] = false
>   c[i], b[i] = 1, 1
>   //  turn = 0 // does not matter
> }
>
> func v() {
>   time.Sleep(time.Duration(1e7 + rand.Int63n(1e7)))
> }
>
> func count(i int) {
>   for k := 0; k < 100; k++ {
> lock(i)
> accu := n
> v()
> accu++
> v()
> n = accu
> v()
> println(s[i], n)
> unlock(i)
> v()
>   }
>   done <- 0
> }
>
> func main() {
>   s[1] = ""
>   for i := 2; i <= N; i++ {
> s[i] = s[i-1] + "   "
>   }
>   for i := 1; i <= N; i++ {
> go count(i)
>   }
>   for i := 1; i <= N; i++ {
> <-done
>   }
> }
> --- >8 
>
> The cause for the "freaking out" of the program without
> those compulsory breaks (of only 1 ns) is absolutely unclear.
>
> Any sort of help is welcome!
>
> Kind regards to everybody,
>
> Christian Maurer
>
>

-- 
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/f83856a2-0661-4425-9861-196b83fcf07f%40googlegroups.com.


[go-nuts] mutual exclusion algorithm of Dijkstra - strange behaviour

2017-10-30 Thread dr . ch . maurer
Dear Go-community,

I noticed a very strange effect by translating the
mutual exclusion algorithm of E. W. Dijkstra to Go.
Reference:
  Cooperating Sequential Processes. Technical Report EWD-123,
  Technological University Eindhoven (1965)
  http://www.cs.utexas.edu/users/EWD/ewd01xx/EWD123.PDF)

Inserting or omitting code lines A and B resp.
changes the behaviour of this program very severely:

With line A and without line B:
  mutual exclusion is not guaranteed,
with line B and without line A:
  lock does not terminate and
with both lines:
  the program works as it should.

--- 8< 
package main

import (
  "math/rand"
  "time"
)

const N = 10 // number of goroutines involved

var (
  turn int
  b, c = make([]int, N+1), make([]int, N+1)
  n= uint(0)
  inCS = make([]bool, N+1)
  s= make([]string, N+1)
  done = make(chan int)
)

func chk(i int) {
  for j := 1; j <= N; j++ {
if j != i && inCS[j] {
  panic("oops")
}
  }
}

func lock(i int) {
  b[i] = 0
L:
  if turn != i {
c[i] = 1
if b[turn] == 1 {
  turn = i
  goto L
}
  }
  time.Sleep(1) // A
  c[i] = 0
  time.Sleep(1) // B
  for j := 1; j <= N; j++ {
if j != i && c[j] == 0 {
  goto L
}
  }
  inCS[i] = true
  chk(i)
}

func unlock(i int) {
  inCS[i] = false
  c[i], b[i] = 1, 1
  //  turn = 0 // does not matter
}

func v() {
  time.Sleep(time.Duration(1e7 + rand.Int63n(1e7)))
}

func count(i int) {
  for k := 0; k < 100; k++ {
lock(i)
accu := n
v()
accu++
v()
n = accu
v()
println(s[i], n)
unlock(i)
v()
  }
  done <- 0
}

func main() {
  s[1] = ""
  for i := 2; i <= N; i++ {
s[i] = s[i-1] + "   "
  }
  for i := 1; i <= N; i++ {
go count(i)
  }
  for i := 1; i <= N; i++ {
<-done
  }
}
--- >8 

The cause for the "freaking out" of the program without
those compulsory breaks (of only 1 ns) is absolutely unclear.

Any sort of help is welcome!

Kind regards to everybody,

Christian Maurer

-- 
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.


dijkstra.go
Description: Binary data