`
genier200
  • 浏览: 22823 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类

windows c thread

 
阅读更多
/* 
	cpp_demo.cpp 
	MSDN帮助手册:http://msdn.microsoft.com/zh-cn/library/ms235302(v=VS.80).aspx
	只是针对CRT(C RunTime)的 _beginthread 和 _beginthreadex 函数创建多线程
	MFC和WIN32 Api创建的线程,请参考其他:
	运行时需要使用管理员身份运行此实例。
	@author:lx
*/

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include <..\crt\src\mtdll.h>

struct parameter 
{
	int max;
	int min;
};
void work(void*);

int file_size[]={512,1024,3068,102400};

int _tmain(int argc, _TCHAR* argv[])
{
	printf("starting......\n");
	const int array_length=sizeof(file_size)/sizeof(file_size[0]);
	struct parameter* args;

	HANDLE threads[array_length];

	for (int i=0;i<array_length;i++)
	{
		args=(struct parameter*)malloc(sizeof(struct parameter));
		if (i==0)
		{
			args->min=0;
			args->max=file_size[0];
		}else
		{
			args->min=file_size[i-1];
			args->max=file_size[i];
		}
		threads[i]=(HANDLE)_beginthread(work,0,args);
	}
	//设置等待
	WaitForMultipleObjects(2, threads, TRUE, INFINITE);
	printf("ending......\n");
	return 0;
}

void work(void* arg)
{
	struct parameter* para=(struct parameter*)arg;
	printf("this is a thread:[min-max]:[%d-%d],pid is %d,id is %d\n",para->min,para->max,_getpid(),_threadid);
	char* cmd=(char*)malloc(1000);
	sprintf(cmd,"fsutil file  createnew c:\\test.%d.bin %d",para->max,para->min);
	printf("%s\n",cmd);
	system(cmd);

}

分享到:
评论

相关推荐

    windows 代码 thread.c

    windows 代码 thread.c 源代码

    windows下面c语言实现的队列

    windows下面用c语言实现的线程调度,消息队列,semaphore等等功能

    WINDOWS/C语言/管道通信实现机制

    Windows管道通信范例 fSuccess = ReadFile(hPipe,ReadData,BUFSIZE,&cbBytesRead,NULL); if (! fSuccess || cbBytesRead == 0) break; else { cout ; } //写数据 fSuccess = WriteFile( hPipe, // handle to pipe s....

    windows服务程序c

    // 该调用是 Windows.Forms 组件设计器所必需的。 InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化 MainThread = new Thread(new ThreadStart(ThreadFunc)); MainThread.Priority = ...

    windows线程之c++封装

    class CThread { public: CThread(); virtual ~CThread(); // 启动线程 DWORD Start(void); // 结束线程 void End(void); // 线程执行函数 virtual void Run(void) = 0; private: static DWORD ...

    Windows系统编程第四版英文版PDF+配套实例程序.rar

    CHAPTER 1 Getting Started with Windows 1 CHAPTER 2 Using the Windows File System and Character I/O 25 CHAPTER 3 Advanced File and Directory...APPENDIX C Performance Results 575 Bibliography 593 Index 597

    Windows System Programming 4th 原版pdf by Hart

    including the file system, process and thread management, interprocess communication, network programming, and synchronization. The examples concentrate on realistic scenarios, and in many cases they...

    s3c2440模拟器realboard v1.1.1(内含rt-thread+GUI演示)

    rbs3c2440.exe(windows版本)是S3C2440开发板模拟器realboard v1.1.1,目前能够支持的外设,覆盖s3c2440的基本功能: 1. 5个时钟和一个看门狗 2. 中断控制器,支持时钟/看门狗中断,串口收发中断,IIC中断等 3. 串口...

    thread_xiancheng.zip_windows 线程_xianchengC

    用c编写的windows环境下的线程的例子,包括源文件和编译生成的目标文件

    mingw-std-threads:Windows上的MinGW GCC当前仍缺少标准线程实现

    mingw-std-threads MinGW GCC当前仍缺少标准C ++ 11线程类的实现。 目标Windows版本 此实现应与Windows XP(无论Service Pack)或更高版本... 例如, #include "mingw.thread.h"替换#include &lt;thread&gt; 。 还提供了C

    windows thread demo

    Simple Multithreaded Application in pure C, Win32 and MFC. using Synchronization: 1. no Synchronization 2. Critical Section Objects 3. Mutex 4. Event ALL sample code write with VC6.0, simplicity!!!

    嵌入式实时操作系统的多线程计算--基于ThreadX和ARM--随书光盘(自己备份)

    Express Logic's ThreadX for Win32 Demo Using Visual C/C++ This demo program is intended for use with the book titled "Real-Time Embedded Multithreading: Using ThreadX and ARM" by Edward L. Lamie.

    thread in c

    #include &lt;windows.h&gt; #include using namespace std; int tickets = 100; int mux1 = 0; int mux2 = 0; DWORD WINAPI func1(LPVOID lp); DWORD WINAPI func2(LPVOID lp); int main() { HANDLE h1,h2; h1 = ...

    C语言多线程实现

    windows下c语言中多线程实现,vs2015编译

    thread4z:Thread4z是一个开源的C++跨平台轻量级跨平台线程库

    封装了线程的创建销毁管理类 CThread , 此包装屏蔽了linux/windows的接口差异部分, 只需要继承该类即可轻松享受并发编程[package of thread creation, destruction and management CThread, this packaging ...

    实验一参考答案.docx

    同步互斥问题实验结果参考答案 内容概要: 实验一 进程管理 ...3、编程:在主线程中调用CreateThread( )创建子线程,并在子线程中显示类似“Thread is running !”等字样。 4、线程互斥的实现 5、线程同步的实现

    Windows环境下32位汇编语言程序设计_随书光盘

    Chapter12\Thread ;用多线程的方式解决上一个程序的问题 Chapter12\Event ;使用事件对象 Chapter12\ThreadSynErr ;一个存在同步问题的多线程程序 Chapter12\ThreadSyn\UseCriticalSection ;使用临界区对象解决多线程...

    dxperience9.1官方汉化

    namespace WindowsFormsApplication1 { static class Program { /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { System.Threading.Thread.CurrentThread.CurrentUICulture = new System....

    thready:C语言中的一个简单的消息传递线程库

    C语言中的一个简单的消息传递线程库。 这是一个小型,高效的跨平台线程库,可处理并发控制,因此您不必这样做。 它可以在Windows,Mac和ubuntu上运行。 内存共享理念 Thready主要围绕参与者模型构建,这意味着每个...

    Windows环境下32位汇编语言程序设计(最新琢石成器版)附属光盘

    Chapter12\Thread ;用多线程的方式解决上一个程序的问题 Chapter12\Event ;使用事件对象 Chapter12\ThreadSynErr ;一个存在同步问题的多线程程序 Chapter12\ThreadSyn\UseCriticalSection ;使用临界区对象解决多...

Global site tag (gtag.js) - Google Analytics