extern "C" void Qt_dispatch_source_signal_lambda(){ char argv[] = "test"; int argc = 1; QDispatchApplication app(argc, (char**)&argv); MU_BEGIN_TEST(Qt_dispatch_source_signal_lambda); EmitterLambda object; // configure the source QDispatchSource src(new QDispatchSourceTypeSignal(&object, SIGNAL(ready()))); src.setTargetQueue(QDispatch::globalQueue(QDispatch::LOW)); src.setHandler([=]{ MU_MESSAGE("Signal was emitted"); if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)) MU_MESSAGE("Executed on low global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) MU_MESSAGE("Executed on default global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) MU_MESSAGE("Executed on high global queue"); else if(QDispatch::currentQueue().native() == dispatch_get_main_queue()) MU_MESSAGE("Executed on main queue"); MU_ASSERT_EQUAL_HEX(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), QDispatch::currentQueue().native()); MU_PASS(""); }); // trigger the signal object.notify(); app.exec(); MU_END_TEST; }
static void test_io_close(int with_timer, bool from_path) { #define chunks 4 #define READSIZE (512*1024) unsigned int i; const char *path = LARGE_FILE; int fd = open(path, O_RDONLY); if (fd == -1) { if (errno == ENOENT) { test_skip("Large file not found"); return; } test_errno("open", errno, 0); test_stop(); } #ifdef F_GLOBAL_NOCACHE if (fcntl(fd, F_GLOBAL_NOCACHE, 1) == -1) { test_errno("fcntl F_GLOBAL_NOCACHE", errno, 0); test_stop(); } #endif struct stat sb; if (fstat(fd, &sb)) { test_errno("fstat", errno, 0); test_stop(); } const size_t size = (size_t)sb.st_size / chunks; const int expected_error = with_timer? ECANCELED : 0; dispatch_source_t t = NULL; dispatch_group_t g = dispatch_group_create(); dispatch_group_enter(g); void (^cleanup_handler)(int error) = ^(int error) { test_errno("create error", error, 0); dispatch_group_leave(g); close(fd); }; dispatch_io_t io; if (!from_path) { io = dispatch_io_create(DISPATCH_IO_RANDOM, fd, dispatch_get_global_queue(0, 0), cleanup_handler); } else { #if DISPATCHTEST_IO_PATH io = dispatch_io_create_with_path(DISPATCH_IO_RANDOM, path, O_RDONLY, 0, dispatch_get_global_queue(0, 0), cleanup_handler); #endif } dispatch_io_set_high_water(io, READSIZE); if (with_timer == 1) { dispatch_io_set_low_water(io, READSIZE); dispatch_io_set_interval(io, 2 * NSEC_PER_SEC, DISPATCH_IO_STRICT_INTERVAL); } else if (with_timer == 2) { t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(0,0)); dispatch_retain(io); dispatch_source_set_event_handler(t, ^{ dispatch_io_close(io, DISPATCH_IO_STOP); dispatch_source_cancel(t); });
int main() { dispatch_queue_t q[PRIORITIES]; int i; #if USE_SET_TARGET_QUEUE test_start("Dispatch Priority (Set Target Queue)"); for(i = 0; i < PRIORITIES; i++) { q[i] = dispatch_queue_create(labels[i], NULL); test_ptr_notnull("q[i]", q[i]); assert(q[i]); dispatch_set_target_queue(as_do(q[i]), dispatch_get_global_queue(priorities[i], 0)); dispatch_queue_set_width(q[i], DISPATCH_QUEUE_WIDTH_MAX_LOGICAL_CPUS); } #else test_start("Dispatch Priority"); for(i = 0; i < PRIORITIES; i++) { q[i] = dispatch_get_global_queue(priorities[i], 0); } #endif for(i = 0; i < PRIORITIES; i++) { submit_work(q[i], &counts[i].count); } dispatch_main(); }
static void CFSocketFinalize (CFTypeRef cf) { CFSocketRef s = (CFSocketRef)cf; #if HAVE_LIBDISPATCH dispatch_queue_t q = dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_cancel(s->_readSource); dispatch_source_cancel(s->_writeSource); // Wait for source handlers to complete // before we proceed to destruction. dispatch_barrier_sync_f(q, NULL, DummyBarrier); if (s->_source != NULL) CFRelease(s->_source); #endif if (s->_socket != -1) { GSMutexLock (&_kCFSocketObjectsLock); CFDictionaryRemoveValue(_kCFSocketObjects, (void*)(uintptr_t) s->_socket); closesocket (s->_socket); GSMutexUnlock (&_kCFSocketObjectsLock); } if (s->_address) CFRelease (s->_address); if (s->_peerAddress) CFRelease (s->_peerAddress); }
static mrb_value mrb_queue_concurrent(mrb_state *mrb, mrb_value self) { mrb_value instance; mrb_sym priority; long priority_value; dispatch_queue_t q; mrb_get_args(mrb, "|n", &priority); if (priority == mrb_intern_cstr(mrb, "high")) { priority_value = DISPATCH_QUEUE_PRIORITY_HIGH; } else if (priority == mrb_intern_cstr(mrb, "low")) { priority_value = DISPATCH_QUEUE_PRIORITY_LOW; } #ifdef DISPATCH_QUEUE_PRIORITY_BACKGROUND else if (priority == mrb_intern_cstr(mrb, "background")) { priority_value = DISPATCH_QUEUE_PRIORITY_BACKGROUND; } #endif else { priority_value = DISPATCH_QUEUE_PRIORITY_DEFAULT; } instance = mrb_queue_create_instance(mrb); q = dispatch_get_global_queue(priority_value, 0); return mrb_queue_set_queue(instance, q); }
WEAK void halide_do_par_for(void (*f)(int, uint8_t *), int min, int size, uint8_t *closure) { halide_gcd_job job; job.f = f; job.closure = closure; job.min = min; dispatch_apply_f(size, dispatch_get_global_queue(0, 0), &job, &halide_do_gcd_task); }
void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::MessageDecoder&) { m_networkAccessManager = new QtNetworkAccessManager(this); ASSERT(!parameters.cookieStorageDirectory.isEmpty() && !parameters.cookieStorageDirectory.isNull()); WebCore::SharedCookieJarQt* jar = WebCore::SharedCookieJarQt::create(parameters.cookieStorageDirectory); m_networkAccessManager->setCookieJar(jar); // Do not let QNetworkAccessManager delete the jar. jar->setParent(0); ASSERT(!parameters.diskCacheDirectory.isEmpty() && !parameters.diskCacheDirectory.isNull()); QNetworkDiskCache* diskCache = new QNetworkDiskCache(); diskCache->setCacheDirectory(parameters.diskCacheDirectory); // The m_networkAccessManager takes ownership of the diskCache object upon the following call. m_networkAccessManager->setCache(diskCache); #if defined(Q_OS_MACX) pid_t ppid = getppid(); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, ppid, DISPATCH_PROC_EXIT, queue); if (source) { dispatch_source_set_event_handler_f(source, parentProcessDiedCallback); dispatch_resume(source); } #endif WebCore::RuntimeEnabledFeatures::setSpeechInputEnabled(false); // We'll only install the Qt builtin bundle if we don't have one given by the UI process. // Currently only WTR provides its own bundle. if (parameters.injectedBundlePath.isEmpty()) { m_injectedBundle = InjectedBundle::create(String()); m_injectedBundle->setSandboxExtension(SandboxExtension::create(parameters.injectedBundlePathExtensionHandle)); QtBuiltinBundle::shared().initialize(toAPI(m_injectedBundle.get())); } }
static void tests(void) { // CFStringRef messageToUser = CFSTR("OK to sync with world?"); // CFStringRef messageToUser = CFSTR("Allow “Emily‘s iPad to use your iCloud Keychain?"); #if !TARGET_IPHONE_SIMULATOR #if TARGET_OS_EMBEDDED CFStringRef our_peer_id = (CFStringRef)MGCopyAnswer(kMGQUserAssignedDeviceName, NULL); #else CFStringRef our_peer_id = CFSTR("🔥💩"); #endif #else CFStringRef our_peer_id = CFSTR("Emily‘s iPad"); #endif CFStringRef messageToUser = CFStringCreateWithFormat(kCFAllocatorDefault, 0, CFSTR("Allow “%@” to use your iCloud Keychain?"), our_peer_id); dispatch_queue_t processQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_group_t work_group = dispatch_group_create(); // Prep the group for exitting the whole shebang. dispatch_group_enter(work_group); dispatch_group_notify(work_group, processQueue, ^ { printf("Exiting via dispatch_group_notify; all work done\n"); CFRunLoopStop(CFRunLoopGetMain()); // exit(0); });
void kcm_session_setup_handler(void) { #ifdef __APPLE__ au_sdev_handle_t *h; dispatch_queue_t bgq; h = au_sdev_open(AU_SDEVF_ALLSESSIONS); if (h == NULL) return; bgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0); dispatch_async(bgq, ^{ for (;;) { auditinfo_addr_t aio; int event; if (au_sdev_read_aia(h, &event, &aio) != 0) continue; /* * Ignore everything but END. This should relly be * CLOSE but since that is delayed until the credential * is reused, we can't do that * */ if (event != AUE_SESSION_END) continue; dispatch_async(dispatch_get_main_queue(), ^{ kcm_cache_remove_session(aio.ai_asid); }); } });
void test_dispatch_latency(unsigned samples, unsigned sleeptime) { unsigned i; uint64_t *lat = (uint64_t *)malloc(sizeof(uint64_t) * 3); uint64_t *history = (uint64_t *)malloc(sizeof(uint64_t) * samples); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_group_t group = dispatch_group_create(); for (i = 0; i < samples; i++) { usleep(sleeptime); /* lat[0] to lat[1] is latency to block execution lat[1] to lat[2] is latency from block execution to block synchronization */ lat[0] = libtime_cpu(); dispatch_group_async(group, queue, ^{ lat[1] = libtime_cpu(); }); dispatch_group_wait(group, DISPATCH_TIME_FOREVER); lat[2] = libtime_cpu(); /* printf("%04u lat[0] = %" PRIu64 "\n", i, lat[0]); printf("%04u lat[1] = %" PRIu64 ", %" PRIu64 "\n", i, lat[1], lat[1] - lat[0]); printf("%04u lat[2] = %" PRIu64 ", %" PRIu64 "\n", i, lat[2], lat[2] - lat[1]); */ history[i] = lat[1] - lat[0]; //history[i] = lat[2] - lat[1]; }
void RequestTimer::setTimeout(int seconds) { m_timeoutSeconds = seconds > 0 ? seconds : 0; cancelTimerSource(); if (!m_timeoutSeconds) { return; } dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); m_timerSource = dispatch_source_create( DISPATCH_SOURCE_TYPE_TIMER, 0, DISPATCH_TIMER_STRICT, q); dispatch_time_t t = dispatch_time(DISPATCH_TIME_NOW, m_timeoutSeconds * NSEC_PER_SEC); dispatch_source_set_timer(m_timerSource, t, DISPATCH_TIME_FOREVER, 0); // Use the timer group as a semaphore. When the source is cancelled, // libdispatch will make sure all pending event handlers have finished before // invoking the cancel handler. This means that if we cancel the source and // then wait on the timer group, when we are done waiting, we know the source // is completely done and it's safe to free memory (e.g., in the destructor). // See cancelTimerSource() above. dispatch_group_enter(m_timerGroup); dispatch_source_set_event_handler(m_timerSource, ^{ onTimeout(); // Cancelling ourselves isn't needed for correctness, but we can go ahead // and do it now instead of waiting on it later, so why not. (Also, // getRemainingTime does use this opportunistically, but it's best effort.) dispatch_source_cancel(m_timerSource); });
// Calculate distances with matrix/matrix operations (BLAS3) void distance(int N, int D, float *data, float *result) { int blockSize = 512; int blockCount = N / blockSize; int remainder = N % blockSize; if (remainder) blockCount++; // Include the ragged edge dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); float *diag = (float *)malloc(sizeof(float) * N); float *C = (float *)malloc(blockCount * blockSize * blockSize * sizeof(float)); dispatch_apply(blockCount, queue, ^(size_t m) { int i, j; int outerDim = blockSize; if (m == blockCount - 1 && remainder) outerDim = remainder; cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, outerDim, outerDim, D, 1, &data[m * blockSize * D], D, &data[m * blockSize * D], D, 0, &C[m * blockSize * blockSize], outerDim); for(i = 0; i < outerDim; i++) diag[m * blockSize + i] = C[m * blockSize * blockSize + i * (outerDim + 1)]; for(i = 0; i < outerDim; i++) for(j = i + 1; j < outerDim; j++) result[utndidx(i + m * blockSize, j + m * blockSize)] = \ sqrt(diag[i + m * blockSize] + diag[j + m * blockSize] - \ 2 * C[m * blockSize * blockSize + j * outerDim + i]); });
static void render(unsigned char *img, int comps, int w, int h, int nsubsamples, int tilew, int tileh) { float *fimg = (float *)malloc(sizeof(float) * w * h * 3); memset((void *)fimg, 0, sizeof(float) * w * h * 3); dispatch_queue_t dque = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); //dispatch_queue_t dque = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_group_t dgroup = dispatch_group_create(); int i, j; for (j = 0; j < h; j += tileh) { for (i = 0; i < w; i += tilew) { void (^renderblock)(void) = ^{ render_tile(img, comps, fimg, w, h, nsubsamples, i, j, tilew, tileh); }; //renderblock(); dispatch_group_async(dgroup, dque, renderblock); } } dispatch_group_wait(dgroup, DISPATCH_TIME_FOREVER); //dispatch_release(dgroup); }
ResourceHandleCFURLConnectionDelegateWithOperationQueue::ResourceHandleCFURLConnectionDelegateWithOperationQueue(ResourceHandle* handle) : ResourceHandleCFURLConnectionDelegate(handle) , m_queue(dispatch_queue_create("com.apple.WebCore/CFNetwork", DISPATCH_QUEUE_SERIAL)) , m_semaphore(dispatch_semaphore_create(0)) { dispatch_queue_t backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); dispatch_set_target_queue(m_queue, backgroundQueue); }
void work3(void *(*f)(int)) { long count = 20; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);//dispatch_queue_create("com.mydomain.myapp.longrunningfunction", DISPATCH_QUEUE_CONCURRENT); //int *r = new int [count];//10000; //for(int i = 0; i < count; i++) r[i] = i; dispatch_apply(count, queue, ^(size_t i) { f(i); });
void dispatch_api() { dispatch_queue_t q = NULL; MU_BEGIN_TEST(dispatch_api); q = dispatch_get_main_queue(); MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_main_queue",q); dispatch_async_f(q, NULL, pass); q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0); MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q); q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0); MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q); q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0); MU_DESC_ASSERT_NOT_NULL_HEX("dispatch_get_global_queue", q); dispatch_main(); MU_END_TEST; }
static int mach_init(const char *service, void **ctx) { struct mach_ctx *ipc; mach_port_t sport; int ret; dispatch_once(&jobqinited, ^{ jobq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); syncq = dispatch_queue_create("heim-ipc-syncq", NULL); });
static void MOToldInstrData(struct oldInstrData *i) { #ifndef __BLOCKS__ int j; #endif MADBE16(&i->numSamples); MADBE16(&i->volFade); #ifdef __BLOCKS__ dispatch_apply(12, dispatch_get_global_queue(0, 0), ^(size_t j) { MOToldEnvRec(&i->volEnv[j]); MOToldEnvRec(&i->pannEnv[j]); });
bool RayTracer::render (const Vec3Df & camPos, const Vec3Df & direction, const Vec3Df & upVector, const Vec3Df & rightVector, float fieldOfView, float aspectRatio, unsigned int screenWidth, unsigned int screenHeight, QImage & image) { Scene* scene = Scene::getInstance(); rayIterator->setCameraInformation(camPos, direction, upVector, rightVector, fieldOfView, aspectRatio, screenWidth, screenHeight); for (unsigned int i = 0; i < screenWidth; i++) { #if defined(__APPLE__) dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); __block vector<QRgb> columnsColor; columnsColor.resize(screenHeight); dispatch_apply(screenHeight, queue, ^(size_t idx) { int j = static_cast<int>(idx); #else vector<QRgb> columnsColor; columnsColor.resize(screenHeight); #if defined(_OPENMP) #pragma omp parallel for #endif for (unsigned int j = 0; j < screenHeight; j++) { #endif std::vector<Ray> rays; rayIterator->raysForPixel(i, j, rays); Vec3Df pixelColor; Vec3Df rayColor; for (const Ray& ray : rays) { raySceneInteraction(ray, *scene, rayColor); pixelColor += rayColor; } pixelColor *= 255/float(rays.size()); QRgb rgb = qRgb(clamp(pixelColor[0], 0, 255), clamp(pixelColor[1], 0, 255), clamp(pixelColor[2], 0, 255)); columnsColor[j] = rgb; #if defined(__APPLE__) }); #else }
int main(int argc, const char *argv[]) { fprintf(stderr, "start\n"); done = dispatch_semaphore_create(0); dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); my_global = 10; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{ my_global = 42; dispatch_semaphore_signal(done); });
static void init_globals(void) { static dispatch_once_t once; dispatch_once(&once, ^{ timerq = dispatch_queue_create("hiem-sipc-timer-q", NULL); timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, timerq); dispatch_source_set_event_handler(timer, ^{ timer_ev(); } ); workq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); eventq = dispatch_queue_create("heim-ipc.event-queue", NULL); });
WEAK int default_do_par_for(void *user_context, halide_task_t f, int min, int size, uint8_t *closure) { halide_gcd_job job; job.f = f; job.user_context = user_context; job.closure = closure; job.min = min; job.exit_status = 0; dispatch_apply_f(size, dispatch_get_global_queue(0, 0), &job, &halide_do_gcd_task); return job.exit_status; }
void CTSetupWithCompletion(ct_completion_block completion) { dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0); dispatch_async(globalQueue, ^{ CTSetupAllSETCards(); CTSetupAllCombinations(); dispatch_async(dispatch_get_main_queue(), ^{ if (completion) { completion(ct_numberOfAllPossibleSETs); } }); });
void test_proc(pid_t bad_pid) { dispatch_source_t proc_s[PID_CNT], proc; int res; pid_t pid, monitor_pid; event_cnt = 0; // Creates a process and register multiple observers. Send a signal, // exit the process, etc., and verify all observers were notified. posix_spawnattr_t attr; res = posix_spawnattr_init(&attr); assert(res == 0); #if HAVE_DECL_POSIX_SPAWN_START_SUSPENDED res = posix_spawnattr_setflags(&attr, POSIX_SPAWN_START_SUSPENDED); assert(res == 0); #endif char* args[] = { "/bin/sleep", "2", NULL }; res = posix_spawnp(&pid, args[0], NULL, &attr, args, NULL); if (res < 0) { perror(args[0]); exit(127); } res = posix_spawnattr_destroy(&attr); assert(res == 0); dispatch_group_t group = dispatch_group_create(); assert(pid > 0); monitor_pid = bad_pid ? bad_pid : pid; // rdar://problem/8090801 int i; for (i = 0; i < PID_CNT; ++i) { dispatch_group_enter(group); proc = proc_s[i] = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, monitor_pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(0, 0)); test_ptr_notnull("dispatch_source_proc_create", proc); dispatch_source_set_event_handler(proc, ^{ long flags = dispatch_source_get_data(proc); test_long("DISPATCH_PROC_EXIT", flags, DISPATCH_PROC_EXIT); event_cnt++; dispatch_source_cancel(proc); }); dispatch_source_set_cancel_handler(proc, ^{ dispatch_group_leave(group); });
static void setRepeatingTimer(struct nodeInstanceData *ctx, const VuoReal seconds, VuoOutputTrigger(fired,VuoInteger)) { if (ctx->timer) cancelRepeatingTimer(ctx); dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); ctx->timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, q); uint64_t nanoseconds = seconds * NSEC_PER_SEC; dispatch_source_set_timer(ctx->timer, dispatch_time(DISPATCH_TIME_NOW, nanoseconds), nanoseconds, 0); dispatch_source_set_event_handler(ctx->timer, ^{ fired(++ctx->eventCount); });
static void resumeAudio(struct nodeInstanceData *context, VuoOutputTrigger(decodedAudio, VuoList_VuoAudioSamples)) { /* audio queue */ if( VuoMovie_containsAudio(context->movie) && context->playbackRate == 1.) { dispatch_queue_t a_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); context->audio_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, a_queue); // audio (plays at a steady rate) dispatch_source_set_timer(context->audio_timer, DISPATCH_TIME_NOW, DISPATCH_TIME_FOREVER, 0); dispatch_source_set_event_handler(context->audio_timer, ^{ playNextAudioFrame(context, decodedAudio); });
static bool clearAllKVS(CFErrorRef *error) { __block bool result = false; const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC; dispatch_queue_t processQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_semaphore_t waitSemaphore = dispatch_semaphore_create(0); dispatch_time_t finishTime = dispatch_time(DISPATCH_TIME_NOW, maxTimeToWaitInSeconds); SOSCloudKeychainClearAll(processQueue, ^(CFDictionaryRef returnedValues, CFErrorRef cerror) { result = (cerror != NULL); dispatch_semaphore_signal(waitSemaphore); });
int main(int argc, const char *argv[]) { dispatch_queue_t queue = dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0); dispatch_group_t group = dispatch_group_create(); __block int sum = 0; for (int i = 0; i < 10; i++) { dispatch_group_async(group, queue, ^{ printf("+%d\n", i); sum += i; }); }
int main() { fprintf(stderr, "Hello world.\n"); dispatch_semaphore_t done = dispatch_semaphore_create(0); barrier_init(&barrier, 2); dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT); dispatch_queue_t bgq = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(bgq, ^{ dispatch_sync(q, ^{ global = 42; }); barrier_wait(&barrier); });
int main(void) { test_start("Dispatch Apply"); volatile __block int32_t count = 0; const int32_t final = 32; dispatch_queue_t queue = dispatch_get_global_queue(0, 0); test_ptr_notnull("dispatch_get_concurrent_queue", queue); dispatch_apply(final, queue, ^(size_t i __attribute__((unused))) { dispatch_atomic_inc(&count); });