Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Потрепаться";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Вниз

Что такое hMutex?   Найти похожие ветки 

 
Dark Elf   (2003-10-27 11:45) [0]

Уважаемые мастера!

Не подскажете ли что такое hMutex и как им пользоваться?

Заранее благодарен за ответ


 
N169   (2003-10-27 11:58) [1]

Это слово из латинских букв.


 
Dark Elf   (2003-10-27 12:00) [2]

Молодец юнга!


 
isko   (2003-10-27 13:06) [3]

похоже на что то знакомое)


 
Сатир   (2003-10-27 14:27) [4]

hMutex: THandle;
Mutex Handle ( MUTal EXclusoins)
Юзается при работе с потоками с использованием мьютексов.

The CreateMutex function creates a named or unnamed mutex object.

HANDLE CreateMutex(

LPSECURITY_ATTRIBUTES lpMutexAttributes, // pointer to security attributes
BOOL bInitialOwner, // flag for initial ownership
LPCTSTR lpName // pointer to mutex-object name
);


Parameters

lpMutexAttributes

Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpMutexAttributes is NULL, the handle cannot be inherited.

Windows NT: The lpSecurityDescriptor member of the structure specifies a security descriptor for the new mutex. If lpMutexAttributes is NULL, the mutex gets a default security descriptor.
Windows 95: The lpSecurityDescriptor member of the structure is ignored.

bInitialOwner

Specifies the initial owner of the mutex object. If TRUE, the calling thread requests immediate ownership of the mutex object. Otherwise, the mutex is not owned.

lpName

Points to a null-terminated string specifying the name of the mutex object. The name is limited to MAX_PATH characters and can contain any character except the backslash path-separator character (\). Name comparison is case sensitive.

If lpName matches the name of an existing named mutex object, this function requests MUTEX_ALL_ACCESS access to the existing object. In this case, the bInitialOwner parameter is ignored because it has already been set by the creating process. If the lpMutexAttributes parameter is not NULL, it determines whether the handle can be inherited, but its security-descriptor member is ignored.
If lpName is NULL, the mutex object is created without a name.

If lpName matches the name of an existing event, semaphore, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because event, mutex, semaphore, and file-mapping objects share the same name space.


 
Сатир   (2003-10-27 14:29) [5]

А вот и лёгкий примерчик по сабжу:

unit Main;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TMainForm = class(TForm)
Button1: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
private
procedure ThreadsDone(Sender: TObject);
end;

TFooThread = class(TThread)
protected
procedure Execute; override;
end;

var
MainForm: TMainForm;

implementation

{$R *.DFM}

const
MaxSize = 128;

var
NextNumber: Integer = 0;
DoneFlags: Integer = 0;
GlobalArray: array[1..MaxSize] of Integer;
hMutex: THandle = 0;

function GetNextNumber: Integer;
begin
Result := NextNumber; // return global var
Inc(NextNumber); // inc global var
end;

procedure TFooThread.Execute;
var
i: Integer;
begin
FreeOnTerminate := True;
OnTerminate := MainForm.ThreadsDone;
if WaitForSingleObject(hMutex, INFINITE) = WAIT_OBJECT_0 then
begin
for i := 1 to MaxSize do
begin
GlobalArray[i] := GetNextNumber; // set array element
Sleep(5); // let thread intertwine
end;
end;
ReleaseMutex(hMutex);
end;

procedure TMainForm.ThreadsDone(Sender: TObject);
var
i: Integer;
begin
Inc(DoneFlags);
if DoneFlags = 2 then // make sure both threads finished
begin
for i := 1 to MaxSize do
{ fill listbox with array contents }
Listbox1.Items.Add(IntToStr(GlobalArray[i]));
CloseHandle(hMutex);
end;
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
hMutex := CreateMutex(nil, False, nil);
TFooThread.Create(False); // create threads
TFooThread.Create(False);
end;

end.



 
DVM   (2003-10-27 18:16) [6]

это название переменной


 
Сатир   (2003-10-27 18:29) [7]

>это название переменной
с чего ты взял?


 
Palladin   (2003-10-27 18:34) [8]


> Сатир © (27.10.03 18:29) [7]

ну а что это тогда?


 
Сатир   (2003-10-27 18:41) [9]

так, обычный оффтопик...



Страницы: 1 вся ветка

Форум: "Потрепаться";
Текущий архив: 2003.11.17;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.01 c
14-56889
TCrash
2003-10-25 13:44
2003.11.17
Завтра день варенья


1-56606
A0th
2003-11-05 17:08
2003.11.17
как работает try...except...


9-56431
wara
2003-05-12 11:33
2003.11.17
Какие данные хранятся вместе с графикой в графических файлах?


14-56851
Романов Р.В.
2003-10-27 10:31
2003.11.17
Завтра день рождения Билла Гейтса


14-56826
REA
2003-10-28 10:33
2003.11.17
В каждой шутке...





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский