Пример #1
0
#! /usr/bin/env python3

import sys, os
from os import getpid, fork
from time import sleep, time
from svipc import sem_init, sem_take, sem_give, sem_cleanup

# create id
sid = int(0x7dcb0000) | getpid()

# create a pool with one semaphore
sem_init(sid, nums=1)

# time unit for test
delay = 0.5


class unit_test(object):
    def __init__(self):
        self.errmsg = ''
        if fork():
            if not self.parent(): print('OK')
            else: print('ERROR', self.errmsg)
        else:
            self.child()
            exit()

    def parent(self):
        return 0

    def child(self):
Пример #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)
Пример #3
0
#! /usr/bin/env python3

import sys, os
from os import getpid, fork
from time import sleep, time
from svipc import sem_init, sem_take, sem_give, sem_cleanup

# create id
sid = int(0x7dcb0000) | getpid()

# create a pool with one semaphore
sem_init(sid,nums=1)

# time unit for test
delay=0.5

class unit_test(object):
  def __init__(self):
    self.errmsg=''
    if fork():
      if not self.parent(): print('OK')
      else: print('ERROR', self.errmsg)
    else:
      self.child()
      exit()
  def parent(self): return 0
  def child(self): pass

class ut1(unit_test):
  def parent(self):
    print('- wait for child forever:')
Пример #4
0
num_ = 10000000

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)