CreateThread,如何使单个函数由多个线程运行? [英] CreateThread, how to have single function ran by multiple threads?

查看:211
本文介绍了CreateThread,如何使单个函数由多个线程运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?我很习惯使用.NET东西,以至于我在C语言中将此Multithreading添加到应用程序中时,我什至没有考虑它.

基本上,似乎只能创建此功能的一个实例.

我在一个单独的包含此函数的库中有函数X.
创建的每个项目都会为该函数创建一个线程.

该函数只有一个实例可以运行(第一个创建的实例).

有任何想法吗?

Is this possible? Im so used to using the .NET stuff, that when im in C adding this Multithreading to an app i didnt even think about it.

Basically only one instance of this function seems to be able to be created.

I have function X in a seperate library that contains this function.
Each item that gets created creates a thread to that function.

Only one instance of that function ever gets run(the one that got created first).

Any ideas?

推荐答案

这是完全可能的.相同的函数在单独的线程中运行,因此每次相同的代码获得单独的堆栈时,这有什么问题?

很难说为什么您的代码只能在一个线程中工作.可能有不同的原因.我需要看一下您的代码示例才能找到答案.

—SA
This is quite possible. The same function runs in a separate thread, so each time the same code gets its separate stack, what''s wrong with that?

It''s quite hard to say why your code works only in one thread. There can be different reasons for that. I need to see you code sample to find out.

—SA


这篇关于CreateThread,如何使单个函数由多个线程运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆