dispatch_sync_gc.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. #include <dispatch/dispatch.h>
  21. #import <Foundation/Foundation.h>
  22. #include <bsdtests.h>
  23. #include "dispatch_test.h"
  24. #if __OBJC_GC__
  25. const size_t final = 50000, desclen = 538892;
  26. #else
  27. const size_t final = 1000, desclen = 8892;
  28. #endif
  29. NSAutoreleasePool *pool = nil;
  30. static void
  31. work(void* ctxt __attribute__((unused)))
  32. {
  33. pool = [[NSAutoreleasePool alloc] init];
  34. NSMutableArray *a = [NSMutableArray array];
  35. dispatch_group_t g = dispatch_group_create();
  36. dispatch_group_async(g, dispatch_get_global_queue(0, 0), ^{
  37. NSUInteger i;
  38. for (i = 0; i < final; i++) {
  39. NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithDecimal:
  40. [[NSNumber numberWithInteger:i] decimalValue]];
  41. dispatch_sync(dispatch_get_main_queue(), ^{
  42. [a addObject:n];
  43. });
  44. }
  45. });
  46. dispatch_group_notify(g, dispatch_get_main_queue(), ^{
  47. test_long("count", [a count], final);
  48. test_long("description length", [[a description] length], desclen);
  49. [pool drain];
  50. test_stop_after_delay((void*)(intptr_t)1);
  51. });
  52. dispatch_release(g);
  53. }
  54. int
  55. main(void)
  56. {
  57. dispatch_test_start("Dispatch Sync GC"); // <rdar://problem/7458685>
  58. dispatch_async_f(dispatch_get_main_queue(), NULL, work);
  59. CFRunLoopRun();
  60. return 0;
  61. }