Thread in WIN32 & Linux
来源:互联网 发布:linux系统管理员招聘 编辑:程序博客网 时间:2024/05/18 23:25
以下是WIN32中的线程创建,主要创建函数在程序中给出说明
#include <iostream>#include <cstdlib>#include <windows.h>DWORD WINAPI FunProc(LPVOID lpParameter){int i(0);while (i++ < 1000){std::cout << " Thread running the " << i << " times" << std::endl;}return 0;}int _tmain(int argc, _TCHAR* argv[]){int j(0);//- 1 - 第一个参数是安全属性结构 //主要控制该线程句柄是否可为进程的子进程继承使用,默认使用NULL时表示不能继承; //若想继承线程句柄,则需要设置该结构体,将结构体的bInheritHandle成员初始化为TRUE;//- 2 - cbStack表示的线程初始栈的大小,若使用0则表示采用默认大小初始化(1M);//- 3 - lpStartAddr表示线程开始的位置,即线程要执行的函数代码,这点有点类似于回调函数的使用;//- 4 - lpvThreadParam用来接收线程过程函数的参数,不需要时可以设置为NULL;//- 5 - fdwCreate表示创建线程时的标志, //CREATE_SUSPENDED表示线程创建后挂起暂不执行,必须调用ResumeThread才可以执行,0表示线程创建之后立即执行//- 6 - lpIDThread用来保存线程的ID;HANDLE hThread_1 = CreateThread(NULL, 0, FunProc, NULL, 0, NULL);CloseHandle(hThread_1);while ( j++ < 1000){std::cout << "Main Thread is running for " << j << " times" << std::endl;}system("pause");return 0;}
以下是linux中的线程创建
#include <stdio.h>#include <pthread.h>#include <ctype.h>#include <Windows.h>void *Function_t(void* Param){pthread_t myid = pthread_self();while (1){printf("线程ID=%d \n", myid);Sleep(2000);}return NULL;}int main(){pthread_t pid;pthread_create(&pid, NULL, Function_t, NULL);while (1){printf("in father process!\n");Sleep(2000);}getchar();return 1;}
0 0
- Thread in WIN32 & Linux
- Thread in Linux
- Thread in linux
- Linux process/thread in practice
- how to create a thread in win32 platform
- Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: no swt-win32-323
- Getting thread count for proc in linux
- c multiple thread programming in linux
- Win32 Thread API学习
- Win32 Thread Information Block
- Exception in thread "main" java.lang.UnsatisfiedLinkError: ca.beq.util.win32.registry.RegistryKey.te
- linux里输入dbca时,出现exception in thread main
- Linux(centOS):Exception in thread "main" java.lang.UnsupportedClassVersionError***
- Linux rpm 报错Thread died in Berkeley DB library
- Migrating Win32 C/C++ applications to Linux on POWER, Part 1: Process, thread
- Serial Communications in Win32
- Icons in Win32
- Hosting ActiveX in Win32
- UIImageView 加入子UIImageView 导致内存泄露的问题
- 总结一些更多的针对webkit的HTML, CSS和Javascript方面的特性.
- 关于Sphinx引擎的一些想法
- Java 项目打包并且发布
- 如何制作Ubuntu SDK Live USB盘 (15.04 vivid)
- Thread in WIN32 & Linux
- C++实现反射机制
- JAVA锁机制
- 使用 getopt() 进行命令行处理
- 搭建Sphinx-for-chinese引擎时遇到的问题 No fields in schema - will not index.
- ios-AutoLayout(自动布局代码控制)简单总结
- sublime配置全攻略
- [LeetCode]13.Roman to Integer
- hdu 1011 Starship Troopers DP