Пример #1
0
        print "consumer:", gs.time(), "start"
        print "consumer:", gs.time(), "read input signal:", self.input.read()
        print "consumer:", gs.time(), "wait for input (write_event)"
        gs.wait(self.input.write_event())
        print "consumer:", gs.time(
        ), "read input signal again:", self.input.read()
        print "consumer:", gs.time(
        ), "double the input value and write to output"
        self.output.write(self.input.read() * 2)
        print "consumer:", gs.time(), "end"

    def __init__(self, input_p=None, output_p=None):
        self.input = input_p
        self.output = output_p
        gs.spawn(self.doit)


# Signals
msg = gs.signal()
reply = gs.signal()

# Module procucer and port binding
p = producer()
p.output = msg
p.input = reply

# Module consumer and positional port binding
c = consumer(msg, reply)

gs.start()
Пример #2
0
    def doit(self):
        print "consumer:", gs.time(), "start"
        print "consumer:", gs.time(), "read input signal:", self.input.read()
        print "consumer:", gs.time(), "wait for input (write_event)"
        gs.wait(self.input.write_event())
        print "consumer:", gs.time(), "read input signal again:", self.input.read()
        print "consumer:", gs.time(), "double the input value and write to output"
        self.output.write(self.input.read()*2)
        print "consumer:", gs.time(), "end"

    def __init__(self, input_p=None, output_p=None):
        self.input = input_p
        self.output = output_p
        gs.spawn(self.doit)


# Signals
msg = gs.signal()
reply = gs.signal()

# Module procucer and port binding
p = producer()
p.output = msg
p.input = reply

# Module consumer and positional port binding
c = consumer(msg, reply)


gs.start()
Пример #3
0
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#   02110-1301  USA
#
# ENDLICENSETEXT

import gs

# signal with initial value
prod = gs.signal(123)
# signal without initial value, defaults to False
cons = gs.signal()

def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "write 3 to prod"
    prod.write(3)
    print "producer:", gs.time(), "read signal cons default:", cons.read()
    print "producer:", gs.time(), "wait for reply (write_event on cons)"
    gs.wait(cons.write_event())
    print "producer:", gs.time(), "read signal cons again:", cons.read()
    print "producer:", gs.time(), "end"

def consumer():
    print "consumer:", gs.time(), "start"
Пример #4
0
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#   02110-1301  USA
#
# ENDLICENSETEXT

import gs

# signal with initial value
prod = gs.signal(123)
# signal without initial value, defaults to False
cons = gs.signal()


def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "write 3 to prod"
    prod.write(3)
    print "producer:", gs.time(), "read signal cons default:", cons.read()
    print "producer:", gs.time(), "wait for reply (write_event on cons)"
    gs.wait(cons.write_event())
    print "producer:", gs.time(), "read signal cons again:", cons.read()
    print "producer:", gs.time(), "end"

Пример #5
0
# dumb GreenScript for testing debugger integration

use_wind = False
to_debug = [False, False, False]


import gs
import sys

mysig = gs.signal(debug=False,name="MySig")

def f(wt,nm):
  it = 0
  while True:
    print nm, "reached iteration", it
    gs.wait(wt,gs.NS)
    it = it + 1
    mysig.write(it)

def g():
  it = 0
  while True:
    print "faster", "reached iteration", it
    gs.wait(33,gs.NS)
    it = it + 1
    print "loop starts"
    for i in range(40):
      print 'p',
      for j in range(1000): pass
    print