Exemple #1
0
# tell it to go
svipc.sem_give(my_semid,id=0)

# play 1

for i in range(3):
   time.sleep(1)
   svipc.sem_give(key=my_semid,id=0)

# play 2

svipc.sem_take(my_semid,0)

for i in range(3):
   msg = svipc.shm_read(my_shmid,id="pingpong",subscribe=-1.0)
   time.sleep(1)
   msg[i]=0
   svipc.shm_write(my_shmid,"pingpong",data=msg,publish=1)
  
# play 3

for i in range(3):
   msg = svipc.msq_rcv(my_msqid,mtype=1234)
   msg[i]=0
   svipc.msq_snd(my_msqid,mtype=5678,data=msg)




Exemple #2
0
n = 32

stoopid=numpy.ones(n)
stoopid[n-1]=n
data = numpy.arange(n).reshape(stoopid)
#print data.shape


# create id
svid0 = 0x7dcb0000 | getpid()
svid1 = svid0+1

# create a pool with one shmaphore
shm_init(svid0,slots=1)
sem_init(svid1,nums=1)

if fork():
  for i in range(num_):
    shm_write(svid0,'slot0',data,publish=0) # shm id's are string ... doh
    sem_take(svid1,0)
else:
  time.sleep(1)
  for i in range(num_):
    d=shm_read(svid0,'slot0',0)
    sem_give(svid1,0)
    ### print d
  exit()

sem_cleanup(svid1)
shm_cleanup(svid0)
Exemple #3
0
# play 1
for i in range(3):
    time.sleep(1)
    sys.stderr.write('P: sem give %d.\n' % i)
    svipc.sem_give(key=my_semid, id=0)

# play 2

sys.stderr.write('P: wait synch from yorick\n')

svipc.sem_take(my_semid, 1)

sys.stderr.write('P: going now\n')

for i in range(3):
    msg = svipc.shm_read(my_shmid, id="pingpong", subscribe=-1.0)
    time.sleep(1)
    msg[i] = 0
    svipc.shm_write(my_shmid, "pingpong", data=msg, publish=1)

# play 3

sys.stderr.write('P: wait synch from yorick\n')
svipc.sem_take(my_semid, 1)
sys.stderr.write('P: going now\n')

for i in range(3):
    sys.stderr.write('P: rcv\n')
    msg = svipc.msq_rcv(my_msqid, mtype=1234)
    msg[i] = 0
    sys.stderr.write('P: snd\n')
Exemple #4
0
n = 32

stoopid = numpy.ones(n)
stoopid[n - 1] = n
data = numpy.arange(n).reshape(stoopid)
#print data.shape

# create id
svid0 = 0x7dcb0000 | getpid()
svid1 = svid0 + 1

# create a pool with one shmaphore
shm_init(svid0, slots=1)
sem_init(svid1, nums=1)

if fork():
    for i in range(num_):
        shm_write(svid0, 'slot0', data,
                  publish=0)  # shm id's are string ... doh
        sem_take(svid1, 0)
else:
    time.sleep(1)
    for i in range(num_):
        d = shm_read(svid0, 'slot0', 0)
        sem_give(svid1, 0)
        ### print d
    exit()

sem_cleanup(svid1)
shm_cleanup(svid0)