<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798358</guid>
        <pubDate>Wed, 08 May 2019 07:21:11 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798358</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798356'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-08T10:13:57+03:00">08.05.19, 07:13</time></span><div class='quote '>реализуй все эти списки-массивы сам</div></div><br>
Спасибо за совет,попробую.]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798356</guid>
        <pubDate>Wed, 08 May 2019 07:13:57 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798356</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798353'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-08T07:03:01+00:00">08.05.19, 07:03</time></span><div class='quote '>Возможно,но пока это на уровне любимого хобби.</div></div><br>
Я бы не стал тратить время, ты мало чему научишься. Лучше всё делать на с++. <br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798353'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-08T07:03:01+00:00">08.05.19, 07:03</time></span><div class='quote '>О,новые слова.....<br>
Буду искать))</div></div><br>
<br>
Если хочешь научиться базовым алгоритмам (по-моему, у тебя именно с ними проблема), просто не используй стандартную библиотеку, реализуй все эти списки-массивы сам.]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798353</guid>
        <pubDate>Wed, 08 May 2019 07:03:01 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798353</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798352'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-08T06:57:15+00:00">08.05.19, 06:57</time></span><div class='quote '>Ну, с одной стороны полезно, для общего развития. Хотя смысла мало, а упустишь в современном программировании много.</div></div><br>
Возможно,но пока это на уровне любимого хобби.<br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798352'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-08T06:57:15+00:00">08.05.19, 06:57</time></span><div class='quote '>Здесь подойдёт только FIFO-стек</div></div><br>
О,новые слова.....<br>
Буду искать))]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798352</guid>
        <pubDate>Wed, 08 May 2019 06:57:15 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798352</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798307'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T15:19:33+00:00">07.05.19, 15:19</time></span><div class='quote '>Это подойдёт для очереди?</div></div><br>
Нет не подойдёт. Здесь подойдёт только FIFO-стек, который реализуется либо как список, либо как циклический массив. <br>
<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798307'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T15:19:33+00:00">07.05.19, 15:19</time></span><div class='quote '>Так уж пал мой взгляд на изучение программирования на Си.Вот и пытаюсь реализовать задумку на этом языке.</div></div><br>
Ну, с одной стороны полезно, для общего развития. Хотя смысла мало, а упустишь в современном программировании много.]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798307</guid>
        <pubDate>Tue, 07 May 2019 15:19:33 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798307</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798301'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T14:42:53+00:00">07.05.19, 14:42</time></span><div class='quote '>Зачем тебе именно Си?</div></div><br>
Так уж пал мой взгляд на изучение программирования на Си.Вот и пытаюсь реализовать задумку на этом языке.<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798301'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T14:42:53+00:00">07.05.19, 14:42</time></span><div class='quote '>Ищет файлы, складывает их имена в очередь</div></div><br>
char **files = (char**)malloc(3e+7 * sizeof(char));<br>
Это подойдёт для очереди?<br>
Если да,то как определить размер (3e+7 * sizeof(char)) ,если я не знаю,сколько я получу строк?]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798301</guid>
        <pubDate>Tue, 07 May 2019 14:42:53 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798301</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798299'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T14:23:54+00:00">07.05.19, 14:23</time></span><div class='quote '>Есть какая-нибудь ссылка на пример или что-нибудь,где подсмотреть,как это делается?</div></div><br>
У меня нет, я не занимался такими задачами.<br>
<br>
Думаю здесь оптимальным будет создать 3 потока:<br>
1-й Ищет файлы, складывает их имена в очередь<br>
2-й Берёт из очереди имя файла, начитывает его небольшими, ~4К, блоками и складывает их в другую очередь (желательно с контролем размера, т.к. чтение быстрее записи)<br>
3-й Берёт блоки из очереди и сохраняет их в соответствующие файлы<br>
<br>
И, лучше решать эту задачу на с++. Зачем тебе именно Си?]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798299</guid>
        <pubDate>Tue, 07 May 2019 14:23:54 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798299</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798249'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-07T06:19:13+00:00">07.05.19, 06:19</time></span><div class='quote '>Обычно такие задачи решаются при помощи пула потоков.</div></div><br>
Есть какая-нибудь ссылка на пример или что-нибудь,где подсмотреть,как это делается?]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798249</guid>
        <pubDate>Tue, 07 May 2019 06:19:13 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798249</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798219'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T20:49:57+00:00">06.05.19, 20:49</time></span><div class='quote '>На диске около 200 txt файлов.<br>
Поиск происходит в 3 цикла с перерывом 5 сек.<br>
Заметил,что в каждом цикле на разных файлах заканчивается вывод.<br>
Иногда попадает на последний на диске(выводит согласно алфавиту),но часто не доходит до него.<br>
</div></div><br>
<br>
Здесь у тебя вроде всё правильно, ошибка где-то в другом месте.<br>
<br>
А вообще - это очень хреновая идея делать по потоку на файл. Обычно такие задачи решаются при помощи пула потоков. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2019-05-07T06:19:58+00:00">07.05.19, 06:19</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798224'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T22:06:52+00:00">06.05.19, 22:06</time></span><div class='quote '>Но на том же сайте упамянутого Майкрософта написано,мол <br>
&quot;Поток в исполняемом файле, который вызывает библиотеку времени выполнения C (CRT), должен использовать функции _beginthreadex и _endthreadex для управления потоками...&quot;<br>
Или это не мой случай?</div></div><br>
<br>
Твой. Только _endthreadex не нужно вызывать, он сам вызовется.]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798224</guid>
        <pubDate>Mon, 06 May 2019 22:06:52 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798224</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798221'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>ЫукпШ &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T21:12:10+00:00">06.05.19, 21:12</time></span><div class='quote '>_beginthreadex - эта функция не является функцией Виндус.<br>
Это некая обёртка вокруг &quot;CreateThread&quot; для ликвидации неких<br>
внутренних проблем потоко-безопасных библиотек Микрософта &#33;</div></div><br>
Но на том же сайте упамянутого Майкрософта написано,мол <br>
&quot;Поток в исполняемом файле, который вызывает библиотеку времени выполнения C (CRT), должен использовать функции _beginthreadex и _endthreadex для управления потоками...&quot;<br>
Или это не мой случай?]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798221</guid>
        <pubDate>Mon, 06 May 2019 21:12:10 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798221</link>
        <description><![CDATA[ЫукпШ: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798055'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T03:32:35+00:00">06.05.19, 03:32</time></span><div class='quote '>Пишу многопоточную программу для поиска файлов.<br>
Для создания потоков использую _beginthreadex.<br>
...<br>
Подскажите,пожалуйста,в чём ошибка?<br>
Компилирую из консоли gcc main.c -o char -static -s -Wall -Wextra -Werror -W</div></div><br>
Можно почитать известную книгу Рихтера, глава 6. (стр 130)<br>
_beginthreadex - эта функция не является функцией Виндус.<br>
Это некая обёртка вокруг &quot;CreateThread&quot; для ликвидации неких<br>
внутренних проблем потоко-безопасных библиотек Микрософта &#33;<br>
А будет ли полезно и чем закончится её применение для библиотек<br>
других производителей других компиляторов вообще не известно.]]></description>
        <author>ЫукпШ</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798219</guid>
        <pubDate>Mon, 06 May 2019 20:49:57 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798219</link>
        <description><![CDATA[Sherman: В общем,основной поток не ждёт завершения &quot;дочерних&quot; потоков.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp;WaitForMultipleObjects(drive, hThreads, TRUE, INFINITE);</div><div class="code_line">&nbsp;&nbsp; &nbsp;WaitForMultipleObjects(find_file, hFileThreads, TRUE, INFINITE);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for(int i = 0; i &#60; find_file; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(hFileThreads[i]);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for(int i = 0; i &#60; drive; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(hThreads[i]);</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
использую это в основном потоке,где <br>
hThreads - потоки функции поиска файлов и записи их нахождения в char *file;(сколько дисков,столько и потоков,но пока проверяю на 1 диске)<br>
hFileThreads - потоки функции вывода вывода char *file в консоль.(стоит 100)<br>
<br>
На диске около 200 txt файлов.<br>
Поиск происходит в 3 цикла с перерывом 5 сек.<br>
Заметил,что в каждом цикле на разных файлах заканчивается вывод.<br>
Иногда попадает на последний на диске(выводит согласно алфавиту),но часто не доходит до него.]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798190</guid>
        <pubDate>Mon, 06 May 2019 15:03:23 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798190</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798184'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T14:03:56+00:00">06.05.19, 14:03</time></span><div class='quote '>Сделай malloc(strlen(...) + 1)</div></div><br>
Сделал так:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unsigned __stdcall SearchFiles2(void* lpszFile)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;char *lpszFileName = (char*)malloc(2048 * sizeof(char));</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcpy(lpszFileName, (char *)lpszFile);</div><div class="code_line">&nbsp;&nbsp; &nbsp;char *path = (char*)malloc(strlen(lpszFileName) * sizeof(char) + 255);</div><div class="code_line">&nbsp;&nbsp; &nbsp;char *temp = (char*)malloc(strlen(lpszFileName) * sizeof(char) + 255);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcpy(path, lpszFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcat(path, &quot;*.*&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">/*...........................................*/</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;FindClose(hand);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(lpszFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(path);</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(temp);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div><br>
Всё остальное без изменения.<br>
Прогнал весь системный диск(примерно 310т. файлов) 3 раза тем же методом.<br>
Ошибка не появилась.<br>
Спасибо за совет)]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798184</guid>
        <pubDate>Mon, 06 May 2019 14:03:56 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798184</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798180'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T13:47:58+00:00">06.05.19, 13:47</time></span><div class='quote '>как грамотно сделать проверку,strlen()?</div></div><br>
Сделай malloc(strlen(...) + 1)]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798180</guid>
        <pubDate>Mon, 06 May 2019 13:47:58 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798180</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798177'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T13:43:36+00:00">06.05.19, 13:43</time></span><div class='quote '>Ты уверен, что у тебя все пути помещаются в MAX_PATH? Поставь проверку</div></div><br>
Нет,не уверен.А если нет,могу ли я вписать 1024,например?<br>
Не будет ли каракулей и т.п.?<br>
Или нужно malloc юзать?<br>
А как грамотно сделать проверку,strlen()?]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798177</guid>
        <pubDate>Mon, 06 May 2019 13:43:36 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798177</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798174'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T13:32:38+00:00">06.05.19, 13:32</time></span><div class='quote '>Спустя пару минут прогона 24 потоков функции,в которой записанные строки выводятся в консоль,выдало ошибку<br>
&quot;Код исключения:	c0000024&quot;</div></div><br>
<br>
Ты уверен, что у тебя все пути помещаются в MAX_PATH? Поставь проверку]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798175</guid>
        <pubDate>Mon, 06 May 2019 13:39:16 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798175</link>
        <description><![CDATA[Sherman: <div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp;Имя события проблемы:APPCRASH</div><div class="code_line">&nbsp;&nbsp;Имя приложения:char.exe</div><div class="code_line">&nbsp;&nbsp;Версия приложения:0.0.0.0</div><div class="code_line">&nbsp;&nbsp;Отметка времени приложения:5cd0387a</div><div class="code_line">&nbsp;&nbsp;Имя модуля с ошибкой:ntdll.dll</div><div class="code_line">&nbsp;&nbsp;Версия модуля с ошибкой:6.3.9600.18821</div><div class="code_line">&nbsp;&nbsp;Отметка времени модуля с ошибкой:59ba8666</div><div class="code_line">&nbsp;&nbsp;Код исключения:c0000024</div><div class="code_line">&nbsp;&nbsp;Смещение исключения:0007d313</div><div class="code_line">&nbsp;&nbsp;Версия ОС:6.3.9600.2.0.0.768.100</div><div class="code_line">&nbsp;&nbsp;Код языка:1049</div></ol></div></div></div></div>]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798174</guid>
        <pubDate>Mon, 06 May 2019 13:32:38 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798174</link>
        <description><![CDATA[Sherman: Спустя пару минут прогона 24 потоков функции,в которой записанные строки выводятся в консоль,выдало ошибку<br>
&quot;Код исключения:	c0000024&quot;<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unsigned __stdcall Thread(void * ffile)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;char fille[MAX_PATH] = { 0 };</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcpy(fille, (CONST char *)ffile);</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(ffile);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;find_file++;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;ReleaseMutex(hMutex);</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;%s\r\n&quot;, fille);</div><div class="code_line">&nbsp;&nbsp; &nbsp;Sleep(find_file * 5L); //небольшая задержка,которая увеличивается,как бы имитация какой-то работы с файлами разного объёма.</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div>]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798168</guid>
        <pubDate>Mon, 06 May 2019 12:59:21 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798168</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798164'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T12:51:40+00:00">06.05.19, 12:51</time></span><div class='quote '>Т.е. ты опять показал какой-то урезанный код?</div></div><br>
Нет,сам не понял как получилось.Сотни раз пишу,переписываю и вышло так,что здесь return NULL,а у меня это.<br>
А код весь,что есть на данный момент.<br>
Приступаю к написанию потоковой функции работы с найденными файлами. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2019-05-06T13:00:23+00:00">06.05.19, 13:00</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798167'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T12:59:15+00:00">06.05.19, 12:59</time></span><div class='quote '>Конечно нужно. Для каждого вызова _beginthreadex должен вызыватся ::CloseHandle, иначе будет нефиговая утечка ресурсов.</div></div><br>
Понял,спасибо. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2019-05-06T13:04:55+00:00">06.05.19, 13:04</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798164'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T12:51:40+00:00">06.05.19, 12:51</time></span><div class='quote '>Вообще, вызов этой функций в конце потока вроде никак не должен влиять (хотя вызывать её не нужно). </div></div><br>
&quot;Поток, который создается с помощью _beginthreadex завершается путем вызова _endthreadex.&quot;<br>
Написано на сайте microsoft, вот я и влепил.]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798167</guid>
        <pubDate>Mon, 06 May 2019 12:59:15 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798167</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798165'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T12:55:14+00:00">06.05.19, 12:55</time></span><div class='quote '>Нужно ли мне закрывать HANDLE перед созданием новых потоков или просто они перепишутся?</div></div><br>
Конечно нужно. Для каждого вызова _beginthreadex должен вызыватся ::CloseHandle, иначе будет нефиговая утечка ресурсов.]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798165</guid>
        <pubDate>Mon, 06 May 2019 12:55:14 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798165</link>
        <description><![CDATA[Sherman: Есть вопрос.<br>
Я создаю поток и пишу его в HANDLE<br>
<br>
И таких 10,например.<br>
Когда их становится 10,жду завершения и обнуляю счётчик<br>
<br>
Нужно ли мне закрывать HANDLE перед созданием новых потоков или просто они перепишутся?<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">if( memory(1) &#60; 86 &amp;&amp; &nbsp; // memory(1) возвращает целое число,равное % загрузки памяти</div><div class="code_line">&nbsp;&nbsp; &nbsp;find_file &#60; THREADS_NUMBER ) &nbsp;// THREADS_NUMBER 10 потоков, find_file плюсуется в функции потока</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; hFileThreads[find_file] = (HANDLE)_beginthreadex(NULL, 0, &amp;Thread, (void *)file, 0, NULL);</div><div class="code_line">}</div><div class="code_line">else</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; WaitForMultipleObjects(find_file, hFileThreads, TRUE, INFINITE);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; find_file = 0; </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; hFileThreads[find_file] = (HANDLE)_beginthreadex(NULL, 0, &amp;Thread, (void *)file, 0, NULL);</div><div class="code_line">}</div></ol></div></div></div></div>]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798164</guid>
        <pubDate>Mon, 06 May 2019 12:51:40 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798164</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798160'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T12:38:25+00:00">06.05.19, 12:38</time></span><div class='quote '>В конце функции потока SearchFiles2 была функция _endthreadex(0); заменил на return 0; всё заработало... .</div></div><br>
<br>
Вообще, вызов этой функций в конце потока вроде никак не должен влиять (хотя вызывать её не нужно). <br>
Т.е. ты опять показал какой-то урезанный код?]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798160</guid>
        <pubDate>Mon, 06 May 2019 12:38:25 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798160</link>
        <description><![CDATA[Sherman: В конце функции потока SearchFiles2 была функция _endthreadex(0); заменил на return 0; всё заработало... .<br>Спасибо за помощь,тему не закрываю,попробую из этого потока создавать потоки на каждый файл.<br>Результаты доложу :D]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798153</guid>
        <pubDate>Mon, 06 May 2019 12:10:29 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798153</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798120'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T10:00:38+00:00">06.05.19, 10:00</time></span><div class='quote '>В этом примере,согласен.<br>
Оставил его по причине того,что на месте printf будут создаваться потоки функции копирования файла,а в ней будет изменяться глобальная переменная</div></div><br>
Там он тоже не нужен. Ты используешь его для доступа к глобальным переменным, можно обойтись без них - передавай параметром в функцию потока не char *, а указатель на структуру.<br>
<br>
а вообще, начни с простого<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unsigned __stdcall SearchFiles2(void* lpszFile)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;start thread\n&quot;);</div><div class="code_line">.......................... </div><div class="code_line">&nbsp;&nbsp; &nbsp;if (hand != INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;%s\n&quot;, data_file.cFileName);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;} while (FindNextFile(hand, &amp;data_file) != 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;FindClose(hand);</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(lpszFile);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;printf(&quot;stop thread\n&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;return NULL;</div><div class="code_line">}</div></ol></div></div></div></div>]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798120</guid>
        <pubDate>Mon, 06 May 2019 10:00:38 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798120</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798118'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Олег М &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T09:39:39+00:00">06.05.19, 09:39</time></span><div class='quote '>Убери мьютекс, совсем. В этой задаче он не нужен.</div></div><br>
В этом примере,согласен.<br>
Оставил его по причине того,что на месте printf будут создаваться потоки функции копирования файла,а в ней будет изменяться глобальная переменная<br>
типа int(счётчик созданных потоков),после чего,разлочиваться.]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798118</guid>
        <pubDate>Mon, 06 May 2019 09:39:39 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798118</link>
        <description><![CDATA[Олег М: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798080'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Sherman &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T06:46:37+00:00">06.05.19, 06:46</time></span><div class='quote '>Но функция не выводит файлы,да и вообще не запускается.<br>
</div></div><br>
Убери мьютекс, совсем. В этой задаче он не нужен.]]></description>
        <author>Олег М</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798080</guid>
        <pubDate>Mon, 06 May 2019 06:46:37 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798080</link>
        <description><![CDATA[Sherman: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=414782&view=findpost&p=3798062'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Qraizer &#064; <time class="tag-quote__quoted-time" datetime="2019-05-06T04:43:31+00:00">06.05.19, 04:43</time></span><div class='quote '>68-я строка абсолютно лишняя.</div></div><br>
Спасибо,исправлю.<br>
Но всё же,как быть с потоками?<br>
Я несколько раз пересматривал на microsoft, просмотрел с десяток примеров на форумах и блогах.<br>
Мой код,вроде,по феншую(что касается создания потоков).<br>
Но функция не выводит файлы,да и вообще не запускается.<br>
При этом (HANDLE)_beginthreadex не возвращает NULL.<br>
Как бы потоки созданы.<br>
Пробовал в 22 строку просто вписать типо printf(&quot;hello&#092;r&#092;n&quot;);<br>
И это не вывелось... .]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798062</guid>
        <pubDate>Mon, 06 May 2019 04:43:31 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798062</link>
        <description><![CDATA[Qraizer: Если я правильно отреверсил,что ты хотел написать, то 68-я строка абсолютно лишняя. Она пытается удалить память, которая ни разу не в хипе.<br>Кроме того, переопределение MAX_PATH ничего тебе не даст. Ограничение на длину буфера в ANSI-функциях WinAPI является фундаментальным. Вроде бы можно это отключить в Win10 где-то в реестре, но подробностей я не знаю. Ограничения на MAX_PATH изначально лишены Unicode-функции WinAPI, только маршрут при этом надо начинать с L&quot;&#092;&#092;?&#092;&quot;]]></description>
        <author>Qraizer</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798055</guid>
        <pubDate>Mon, 06 May 2019 03:32:35 +0000</pubDate>
        <title>Не работает функция в потоке _beginthreadex</title>
        <link>https://forum.sources.ru/index.php?showtopic=414782&amp;view=findpost&amp;p=3798055</link>
        <description><![CDATA[Sherman: Пишу многопоточную программу для поиска файлов.<br>
Для создания потоков использую _beginthreadex.<br>
Но программа запускается и через некоторое время завершается(без ошибок),а должна выводить путь к файлам в консоль.<br>
Без создания потоков(при работе в основном потоке программы) всё работает,файлы находятся и выводятся.<br>
Подскажите,пожалуйста,в чём ошибка?<br>
Компилирую из консоли gcc main.c -o char -static -s -Wall -Wextra -Werror -W<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">#include &#60;stdio.h&#62;</div><div class="code_line">#include &#60;stdlib.h&#62;</div><div class="code_line">#include &#60;windows.h&#62;</div><div class="code_line">#include &#60;sys/stat.h&#62;</div><div class="code_line">#include &#60;assert.h&#62;</div><div class="code_line">#include &#60;signal.h&#62;</div><div class="code_line">#include &#60;unistd.h&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">#ifndef MAX_PATH</div><div class="code_line">#define MAX_PATH 1024</div><div class="code_line">#endif</div><div class="code_line">&nbsp;</div><div class="code_line">HANDLE hMutex;</div><div class="code_line">&nbsp;</div><div class="code_line">int find_file = 0, drive = 0;</div><div class="code_line">&nbsp;</div><div class="code_line">unsigned __stdcall SearchFiles2(void* lpszFile)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;CONST char *lpszFileName = (CONST char *)lpszFile;</div><div class="code_line">&nbsp;&nbsp; &nbsp;char path[MAX_PATH] = { 0 };</div><div class="code_line">&nbsp;&nbsp; &nbsp;char temp[MAX_PATH] = { 0 };</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcpy(path, lpszFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp;strcat(path, &quot;*.*&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE hand;</div><div class="code_line">&nbsp;&nbsp; &nbsp;WIN32_FIND_DATA data_file;</div><div class="code_line">&nbsp;&nbsp; &nbsp;hand = FindFirstFile(path, &amp;data_file);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if (hand != INVALID_HANDLE_VALUE)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!strncmp(data_file.cFileName, &quot;.&quot;, 1) || !strncmp(data_file.cFileName, &quot;..&quot;, 2))</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;continue;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (data_file.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcpy(path, lpszFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcat(path, data_file.cFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcat(path, &quot;\&quot;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcpy(temp, path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strlwr(temp);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (!lstrcmp(temp, &quot;c:\windows\&quot;) == 0)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SearchFiles(path);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WaitForSingleObject(hMutex, INFINITE);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;char *file = (char*)malloc(strlen(lpszFileName) + strlen(data_file.cFileName) + 64);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assert(file);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcpy(file, lpszFileName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;strcat(file, data_file.cFileName);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;%s\r\n&quot;, file);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReleaseMutex(hMutex);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;} while (FindNextFile(hand, &amp;data_file) != 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;&nbsp; &nbsp;FindClose(hand);</div><div class="code_line">&nbsp;&nbsp; &nbsp;free(lpszFile);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return NULL;</div><div class="code_line">}</div><div class="code_line">&nbsp;</div><div class="code_line">int main(void)</div><div class="code_line">{</div><div class="code_line">&nbsp;&nbsp; &nbsp;char buf[BUF_PATH] = { 0 };</div><div class="code_line">&nbsp;&nbsp; &nbsp;char drives[32][10] = { 0 };</div><div class="code_line">&nbsp;&nbsp; &nbsp;GetLogicalDriveStringsA(sizeof(buf), buf);</div><div class="code_line">&nbsp;&nbsp; &nbsp;for (char *s = buf; *s; s += strlen(s) + 1)</div><div class="code_line">&nbsp;&nbsp; &nbsp;{</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;strcpy(drives[drive], s);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;drive++;</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;HANDLE hThreads[drive];</div><div class="code_line">&nbsp;&nbsp; &nbsp;hMutex = CreateMutex(NULL, FALSE, NULL);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for(int i = 0; i &#60; drive; i++) {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;hThreads[i] = (HANDLE)_beginthreadex(NULL, 0, &amp;SearchFiles2, (void *)drives[i], 0, NULL);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if(NULL == hThreads[i])</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;printf(&quot;Failed to create thread.\r\n&quot;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;WaitForMultipleObjects(drive, hThreads, TRUE, INFINITE);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;for(int i = 0; i &#60; drive; i++)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;CloseHandle(hThreads[i]);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;CloseHandle(hMutex);</div><div class="code_line">&nbsp;&nbsp; &nbsp; </div><div class="code_line">&nbsp;&nbsp; &nbsp;return 0;</div><div class="code_line">}</div></ol></div></div></div></div>]]></description>
        <author>Sherman</author>
        <category>C/C++: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	