コード例 #1
0
ファイル: sem-demo3.py プロジェクト: mdcb/yp-svipc
class ut5(unit_test):
    def parent(self):
        print('- try take semaphore (available):')
        sleep(delay)
        s = sem_take(sid, 0, wait=0)
        self.errmsg = 'sem was not available'
        return s

    def child(self):
        sem_give(sid, 0)


class ut6(unit_test):
    def parent(self):
        print('- try take semaphore (non-available):')
        s = sem_take(sid, 0, wait=0)
        self.errmsg = 'sem was available'
        return not s

    def child(self):
        pass


ut1()
ut2()
ut3()
ut4()
ut5()
ut6()
sem_cleanup(sid)
コード例 #2
0
ファイル: shm-demo.py プロジェクト: mdcb/yp-svipc
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
ファイル: sem-demo3.py プロジェクト: mdcb/yp-svipc
    for i in range(10):
      sem_give(sid,0)

class ut5(unit_test):
  def parent(self):
    print('- try take semaphore (available):')
    sleep(delay)
    s = sem_take(sid, 0, wait=0)
    self.errmsg='sem was not available'
    return s 
  def child(self):
    sem_give(sid,0)

class ut6(unit_test):
  def parent(self):
    print('- try take semaphore (non-available):')
    s = sem_take(sid, 0, wait=0)
    self.errmsg='sem was available'
    return not s 
  def child(self):
    pass


ut1()
ut2()
ut3()
ut4()
ut5()
ut6()
sem_cleanup(sid)
コード例 #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)