关于API
CreateMutex(
lpMutexAttributes: PSecurityAttributes; {a pointer to security attributes}
bInitialOwner: BOOL; {flag for the initial ownership}
lpName: PChar {mutex object name}
): THandle; {returns a handle of the mutex object}
的详细帮助你可以参看msdn
我给你个例子:function ThreadFunc0(Info: Pointer): Integer; stdcall
var
ICount: Integer; // general loop counter
CountStr: string; // holds a string representation of the counter
begin
{wait for the mutex to become signaled. the mutex is created signaled so
this thread gets ownership of the mutex and starts immediately}
WaitForSingleObject(Form1.MutexHandle, INFINITE); {start a counter to display something} for ICount := 1 to 10000 do
begin
CountStr := IntToStr(ICount);
Form1.Canvas.TextOut(10, 10, 'Thread 1 '+CountStr);
end; {Release ownership of the mutex so the other threads can fire}
ReleaseMutex(Form1.MutexHandle);
ExitThread(1);
end;function ThreadFunc1(Info: Pointer): Integer; stdcall
var
ICount: Integer; // general loop counter CountStr: string; // holds a string representation of the counter
begin
{wait for the mutex to become signaled. the mutex is created signaled so
this thread gets ownership of the mutex and starts immediately}
WaitForSingleObject(Form1.MutexHandle, INFINITE); {start a counter to display something}
for ICount := 1 to 10000 do
begin
CountStr := IntToStr(ICount); Form1.Canvas.TextOut(110, 10, 'Thread 2 '+CountStr);
end; {Release ownership of the mutex so the other threads can fire}
ReleaseMutex(Form1.MutexHandle);
ExitThread(2);
end;
CreateMutex(
lpMutexAttributes: PSecurityAttributes; {a pointer to security attributes}
bInitialOwner: BOOL; {flag for the initial ownership}
lpName: PChar {mutex object name}
): THandle; {returns a handle of the mutex object}
的详细帮助你可以参看msdn
我给你个例子:function ThreadFunc0(Info: Pointer): Integer; stdcall
var
ICount: Integer; // general loop counter
CountStr: string; // holds a string representation of the counter
begin
{wait for the mutex to become signaled. the mutex is created signaled so
this thread gets ownership of the mutex and starts immediately}
WaitForSingleObject(Form1.MutexHandle, INFINITE); {start a counter to display something} for ICount := 1 to 10000 do
begin
CountStr := IntToStr(ICount);
Form1.Canvas.TextOut(10, 10, 'Thread 1 '+CountStr);
end; {Release ownership of the mutex so the other threads can fire}
ReleaseMutex(Form1.MutexHandle);
ExitThread(1);
end;function ThreadFunc1(Info: Pointer): Integer; stdcall
var
ICount: Integer; // general loop counter CountStr: string; // holds a string representation of the counter
begin
{wait for the mutex to become signaled. the mutex is created signaled so
this thread gets ownership of the mutex and starts immediately}
WaitForSingleObject(Form1.MutexHandle, INFINITE); {start a counter to display something}
for ICount := 1 to 10000 do
begin
CountStr := IntToStr(ICount); Form1.Canvas.TextOut(110, 10, 'Thread 2 '+CountStr);
end; {Release ownership of the mutex so the other threads can fire}
ReleaseMutex(Form1.MutexHandle);
ExitThread(2);
end;
解决方案 »
- 求助:有关用append向数据库的表中追加记录的问题?
- 关于文本文件的操作.知道的请进来指点一下~!
- 问个菜鸟问题,关于连接远程数据库查询?????
- 排序问题,急!各位大虾请赐教!
- 请教:怎样在Access2000数据库中建表呢,那那些类和方法呢?最好有例子!多谢!:)
- 在线等高手帮忙 VB\VC转DELPHI
- 如何使一个窗体总是得到焦点,禁止其它程序得到焦点。
- 虚拟机sqlserver连不上!
- 如何把文件做为附件,保存到数据库里,就像发邮件的附件一样
- 希望能在广州找一份能学习编程的工作,哪怕是软件测试员都可以
- 特困县的程序员近况,望大家多多支持!
- 哪里有Delphi6 Developer's Guide的源码
var
ICount: Integer; // general loop counter
CountStr: string; // holds a string representation of the counter
LocalMutexHandle: THandle; // holds a handle to the mutexbegin
{open a Handle to the mutex from this thread}
LocalMutexHandle := OpenMutex(MUTEX_ALL_ACCESS, FALSE, 'MyMutex'); {take ownership of the mutex. this will wait until the mutex is signaled}
WaitForSingleObject(LocalMutexHandle, INFINITE); {start a counter to display something}
for ICount := 1 to 10000 do
begin
CountStr := IntToStr(ICount);
Form1.canvas.TextOut(210, 10, 'Thread 3 '+CountStr); end; {Release ownership of the mutex}
ReleaseMutex(LocalMutexHandle); {close the mutex handle}
CloseHandle(LocalMutexHandle);
ExitThread(3);
end;procedure TForm1.CreateThreadClick(Sender: TObject);
var
ThreadId0, ThreadId1, ThreadId2: Integer; // holds thread identifiers
begin
{Create the mutex with the name MyMutex. the mutex is signaled
so the first thread will start immediately} MutexHandle := CreateMutex(nil, False, 'MyMutex'); {Create the first thread, and start it immediately}
ThreadHandle := Windows.CreateThread(nil, 0, @ThreadFunc0, nil, 0, ThreadId0); {Create the second thread, and start it immediately}
ThreadHandle1 := Windows.CreateThread(nil,0, @ThreadFunc1, nil, 0, ThreadId1); {Create the third thread, and start it immediately}
ThreadHandle2 := Windows.CreateThread(nil,0, @ThreadFunc2, nil, 0, ThreadId2); {Stop the main thread for a short time so that the other threads get
a chance to take ownership of the mutex before the main thread
calls WaitForSingleObject}
Sleep(1000); {Take ownership of the mutex; this will wait until the mutex is signaled}
WaitForSingleObject(MutexHandle, INFINITE); {Close the mutexHandle so that this will work again}
CloseHandle(MutexHandle);
end;
这个stdcall是什么东西啊,是什么意思啊!!???