ctypes Example:ΒΆ

You need the following steps to utilize the module:

  1. dynamically linked library is loaded by shared_atomic.loaddll(),

    atomic = shared_atomic.loaddll()

  2. define shared ctypes between processes / threads

    v = multiprocessing.Value(ctypes.c_long, 100, lock=False)

    a = multiprocessing.Array(ctypes.c_long, 100, lock=False)

    if only threads are needed

    a = ctypes.c_long(100)

  3. Get the pointer of the shared variables by ctypes.byref

    aref = ctypes.byref(a, 0)

  4. pass the pointer to atomic functions


    processlist = []

    for i in range(10000):

        processlist.append(Process(target=atomic.long_get_and_set, args=(aref,ctypes.c_long(100))))

    for i in range(10000):


    for i in range(10000):