We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tiny c compiler cannot run in multi-threads,how to solve it?
The text was updated successfully, but these errors were encountered:
示例代码如下,程序会崩溃,报0xC0000005
#define NUM_THREADS 10
void compile_thread(char *filename) { TCCState *s = tcc_new(); if (!s) { fprintf(stderr, "Could not create TCC state\n"); exit(1); }
tcc_set_output_type(s, TCC_OUTPUT_EXE);
if (tcc_compile_string(s, "int main() { return 0; }") == -1) { fprintf(stderr, "Failed to compile code\n"); exit(1); } tcc_delete(s); }
DWORD WINAPI compile_worker(LPVOID arg) { char filename[100]; sprintf(filename, "output_%d.c", (int)arg); compile_thread(filename); return 0; }
int _tmain(int argc, char* argv[]) { /运行代码/ HANDLE hThread[NUM_THREADS]; for (int i = 0; i < NUM_THREADS; i++) { hThread[i] = CreateThread(NULL, 0, compile_worker, (LPVOID)i, 0, NULL); }
for (int i = 0; i < NUM_THREADS; i++) { WaitForSingleObject(hThread[i], INFINITE); CloseHandle(hThread[i]);
printf("线程%d结束\n", i + 1);
}
getchar(); }
Sorry, something went wrong.
No branches or pull requests
tiny c compiler cannot run in multi-threads,how to solve it?
The text was updated successfully, but these errors were encountered: