| 34 | } |
| 35 | |
| 36 | int main() |
| 37 | { |
| 38 | // This test should be run with a prewarmed pool of size 4. None |
| 39 | // of the threads are allocated yet. |
| 40 | assert(EM_ASM_INT(return PThread.unusedWorkers.length) == 4); |
| 41 | assert(EM_ASM_INT(return Object.keys(PThread.pthreads).length) == 0); |
| 42 | |
| 43 | CreateThread(0); |
| 44 | |
| 45 | // We have one running thread, allocated on demand. |
| 46 | assert(EM_ASM_INT(return PThread.unusedWorkers.length) == 3); |
| 47 | assert(EM_ASM_INT(return Object.keys(PThread.pthreads).length) == 1); |
| 48 | |
| 49 | for (int i = 1; i < 5; ++i) { |
| 50 | CreateThread(i); |
| 51 | } |
| 52 | |
| 53 | // All the preallocated workers should be used. |
| 54 | // We can't join the threads or we'll hang forever. The main thread |
| 55 | // won't give up the thread to let the 5th thread be created. This is |
| 56 | // solved in non-test cases by using PROXY_TO_PTHREAD, but we can't |
| 57 | // do that here since we need to eval the length of the various pthread |
| 58 | // arrays. |
| 59 | assert(EM_ASM_INT(return Object.keys(PThread.pthreads).length) == 5); |
| 60 | assert(EM_ASM_INT(return PThread.unusedWorkers.length) == 0); |
| 61 | |
| 62 | return 0; |
| 63 | } |
nothing calls this directly
no test coverage detected