Esempio n. 1
0
        private static void init()
        {
            registerInit("LockOSThreadMain", () =>
            {
                // init is guaranteed to run on the main thread.
                mainThread = C.pthread_self();
            });
            register("LockOSThreadMain", LockOSThreadMain);

            registerInit("LockOSThreadAlt", () =>
            {
                // Lock the OS thread now so main runs on the main thread.
                runtime.LockOSThread();
            });
            register("LockOSThreadAlt", LockOSThreadAlt);
        }
Esempio n. 2
0
        public static void LockOSThreadAlt()
        {
            // This is running locked to the main OS thread.

            C.pthread_t subThread = default;
            var         ready     = make_channel <bool>(1L);

            C.threadExited = 0L;
            go_(() => () =>
            {
                // This goroutine must be running on a new thread.
                runtime.LockOSThread();
                subThread = C.pthread_self();
                // Register a pthread destructor so we can tell this
                // thread has exited.
                ref C.pthread_key_t key = ref heap(out ptr <C.pthread_key_t> _addr_key);
                C.pthread_key_create(_addr_key, new ptr <ptr <array <byte> > >(@unsafe.Pointer(C.setExited)));
                C.pthread_setspecific(key, @unsafe.Pointer(@new <int>()));
                ready.Send(true);
                // Exit with the thread locked.
            } ());