Guest User

Untitled

a guest
Aug 8th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. Swiftloke 21:33:47
  2. Can I kill a thread by getting its handle and doing svcCloseHandle?
  3. profi200 21:37:40
  4. Try it? I'm not sure what the effect will be (it's not the intended way at all). A duplicate handle will just be closed of course.
  5. Swiftloke 21:40:48
  6. How am I supposed to forcefully shut down a thread, then?
  7. That way returns 0, but has no effect. Huh
  8. @yellows8 21:42:04
  9. you can't
  10. Swiftloke 21:42:14
  11. Yeah that's what I thought :(
  12. Would make my code sooo much cleaner but oh well
  13. profi200 21:46:23
  14. The kernel is designed this way unfortunately.
  15. calc84 21:48:03
  16. Force-killing threads is almost always bad design anyway
  17. Swiftloke 21:48:07
  18. Why is that? I know killing threads is generally speaking a bad idea but there are valid use cases for it
  19. (Such as killing worker threads)
  20. Swiftloke 21:49:34
  21. And while we're on the topic of threads...
  22. calc84 21:49:39
  23. But the thing is, you have to guarantee that the workers aren't working
  24. Swiftloke 21:49:56
  25. I've got this long standing bug in my app that started when I started talking to SRV
  26. calc84 21:49:58
  27. And at that rate, they might as well be waiting on an event while they're idle
  28. Swiftloke 21:50:36
  29. The moment I run srvEnableNotification some nasty stuff starts happening when the app closes
  30. It seems that the libctru apt thread doesn't receive the shutdown signal, or at least, that's my theory
  31. It'll end up at line 331, on svcWaitSynchronizationN
  32. And it'll sit there for quite a long time, usually around 30 seconds
  33. https://github.com/Swiftloke/ModMoon/blob/master/source/srv.cpp#L15
  34. I've made sure it's not srvInit nor the worker thread
  35. It's *only* when I run srvEnableNotification
  36. (gdb) backtrace
  37. #0 svcWaitSynchronizationN () at /home/davem/projects/devkitpro/pacman-packages/libctru/src/source/svc.s:271
  38. #1 0x00129658 in aptEventHandler (arg=<optimized out>)
  39. at /home/davem/projects/devkitpro/pacman-packages/libctru/src/source/services/apt.c:331
  40. #2 0x001256f4 in _thread_begin (arg=<optimized out>)
  41. at /home/davem/projects/devkitpro/pacman-packages/libctru/src/source/thread.c:37
  42. #3 0x00000000 in ?? ()
  43. Backtrace stopped: previous frame identical to this frame (corrupt stack?)
  44. profi200 21:52:53
  45. Verified in a minimum test case?
  46. Swiftloke 21:53:18
  47. This is the only thread that's still running, thread 1 is in svcSleepThread after _appExit
  48. → Sektor has joined
  49. Swiftloke 21:53:31
  50. You mean hooking up a tiny test app? Sure I can do that
  51. profi200 21:53:40
  52. Yes.
  53. To rule out bugs in libctru.
  54. Swiftloke 21:59:22
  55. Can confirm it still happens. Shut down in about 18.5 seconds.
  56. https://pastebin.com/yXmSRfc4
  57. Anything stupid here?
  58. Commenting out srvEnableNotification makes exit instant
  59. @yellows8 22:01:34
  60. waitsync on that handle?
  61. Swiftloke 22:02:48
  62. The way the real code works is by starting a separate thread to wait on that handle then run a callback based on that notification it is
  63. That thread isn't the problem. It shuts down instantly.
  64. profi200 22:03:14
  65. Keep in mind you need to release resources.
  66. Swiftloke 22:04:15
  67. That occurred to me but I don't see a function to release the semaphore
  68. @yellows8 22:04:36
  69. close-handle
  70. Swiftloke 22:05:01
  71. WaitSynchronization doesn't help, I'll try that
  72. profi200 22:07:15
  73. That srvInit() is not needed btw. It's done internally already.
  74. Swiftloke 22:12:58
  75. Oh huh
  76. Well sorry that took so long
  77. But
  78. CloseHandle doesn't help
  79. profi200 22:17:09
  80. And with srvInit() removed?
  81. Swiftloke 22:19:25
  82. Doesn't help
  83. Is it safe to assume that this is a libctru bug, or is there something else to try?
  84. profi200 22:21:57
  85. Disable notifications before exiting? I'm not sure why this would cause that delay.
  86. Swiftloke 22:22:36
  87. There's no disable function in ctrulib
  88. profi200 22:22:50
  89. Hmm, ok.
  90. ← PaperDerp has left (Read error: Operation timed out)
  91. Swiftloke 22:24:00
  92. Or at all, just checked 3dbrew
  93. profi200 22:24:04
  94. So it's probably a bug. Try to test if it works correctly (ignoring the delay problem).
  95. Swiftloke 22:24:37
  96. Oh it works fine. In the main code I can receive events 0x208 and 0x20A (cartridge inserted/removed) without issue using that callback stuff
  97. → PaperDerp has joined
  98. ← PaperDerp has left (Client Quit)
  99. profi200 22:25:51
  100. Yeah, dunno what's causing the delay. It at least works.
  101. Swiftloke 22:26:20
  102. Problem is, this is kind of unacceptable to ship, one of my testers has said that it takes minutes to shut down
  103. So, ugh
  104. My theory is that this SRV thread gets the shutdown signal which causes APT to not receive it, somehow
  105. Seeing as the thread that waits on that semaphore closes immediately
  106. profi200 22:29:59
  107. What if you pass it through to the main() loop and break out of it if you receive it?
  108. Swiftloke 22:40:26
  109. Removing the main loop then doing svcWaitSynchronization and immediately exiting when it occurs causes no change.
  110. For that example I triggered an event by inserting a cartridge.
  111. Event 0x208
  112. → PaperDerp has joined
  113. profi200 22:42:11
  114. Well, then i have no idea. Could be in libctru or could be a srv bug maybe.
  115. Swiftloke 22:46:29
  116. Ah, OK... Well, if anyone has any great ideas while I'm gone, please let me know. This has been bothering me since June and I haven't been able to find a good answer for it.
  117. Swiftloke 22:47:31
  118. Here's what I've got now
  119. https://pastebin.com/Cn9MVLFL
Advertisement
Add Comment
Please, Sign In to add comment