X-Git-Url: https://git.saurik.com/apple/libdispatch.git/blobdiff_plain/d4e0f4aade4f18254fb326a5aa6c521fad1930d2..24954c793bca436d612851de3a460c72ef1f7b6d:/testing/dispatch_overcommit.c diff --git a/testing/dispatch_overcommit.c b/testing/dispatch_overcommit.c new file mode 100644 index 0000000..af5e59a --- /dev/null +++ b/testing/dispatch_overcommit.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +#include "dispatch_test.h" + +int32_t count = 0; +const int32_t final = 32; + +int +main(void) +{ + test_start("Dispatch Overcommit"); + + dispatch_queue_attr_t attr = dispatch_queue_attr_create(); + test_ptr_notnull("dispatch_queue_attr_create", attr); + dispatch_queue_attr_set_flags(attr, DISPATCH_QUEUE_OVERCOMMIT); + + int i; + for (i = 0; i < final; ++i) { + char* name; + asprintf(&name, "test.overcommit.%d", i); + + dispatch_queue_t queue = dispatch_queue_create(name, attr); + test_ptr_notnull("dispatch_queue_create", queue); + free(name); + + dispatch_async(queue, ^{ + OSAtomicIncrement32(&count); + if (count == final) { + test_long("count", count, final); + test_stop(); + } else { + while (1); // spin + } + }); + } + + dispatch_main(); + + return 0; +}