Dev c++使用windows.h的简单线程示例
Simple threads example for Dev C++ using windows.h
我第一次尝试学习多线程,但我看到的大多数例子都有一个thread.h
头文件。Dev c++中没有。
我找到了这篇文章,它说您可以使用windows.h
来完成它。遗憾的是它没有提供任何示例程序。有人可以提供一个例子程序,使用线程函数在windows.h
或任何其他广泛使用的头文件,并存在于Dev c++ ?Thank You
Best option is to do threading in c or c++ use pthread.h header file
example work on gcc or dev c++
#include <stdio.h>
#include <stdlib.h>
#include<pthread.h>
int i=0;
void* fun()
{
for(i=0;i<100;i++)
printf("nThe thread 1 is running");
}
void* van()
{
for(i=0;i<100;i++)
printf("nthread 2 is running ");
}
int main()
{
pthread_t t1,t2;
pthread_create(&t1,NULL,fun,NULL);
pthread_create(&t2,NULL,van,NULL);
printf("nI'm in mainn");
pthread_join(t2,NULL);
return 0;
}
windows.h
有一个叫做CreateThread().
的函数
它的签名和其他信息可以在这里看到。
你需要一个回调函数,它将在你启动线程时开始执行。NULL
可以传递给第一个lpThreadAttributes
参数。
HANDLE WINAPI CreateThread(
_In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
_In_ SIZE_T dwStackSize,
_In_ LPTHREAD_START_ROUTINE lpStartAddress,
_In_opt_ LPVOID lpParameter,
_In_ DWORD dwCreationFlags,
_Out_opt_ LPDWORD lpThreadId
);
相关文章:
- 在C/C++中执行"_dl_init"(程序初始化)是单线程的吗
- 特定对象文件的单线程生成
- 如何在类中同时运行某些内容(在单线程平台中)?
- 使用 GCC 10 进行简单协程泄漏
- GDB 8.1 无法在单线程简单程序中跟踪 std::string 变量的值
- 双线程应用比单线程应用慢 C++ (VC++ 2010 Express).如何解决?
- ASIO - 如何停止基于简单协程的服务器?
- OpenMP:共享同一算法的单线程和多线程实现
- std::原子布尔值或普通全局布尔值在单线程中很好吗?
- 重写多线程事件驱动的C 程序以使用单线程Boost :: Asio
- 简单线程程序的链接器错误(缺少boost_chrono符号)
- C++多线程操作比单线程慢
- 多线程和单线程代码维护
- 线程池的计时测试:单线程 vs 回调 tp vs 未来 tp
- 在 Linux 中从单独的单线程进程生成多线程进程时出现问题
- C++多线程性能比单线程代码慢
- 即使在单线程程序中,共享指针是否在引用计数中使用原子操作
- 从单线程到多线程图像处理
- 单线程共享指针,可简单地包含在大型项目中
- 当运行一个简单的单线程C++程序时,是否可以消除Linux机器的抖动