Win32 has conditions, however it's Vista/2008 and on:
http://msdn.microsoft.com/en-us/library/ms682052(VS.85).aspx
So it won't be available on lower end systems. Thread conditions are
basically "wait until this thing happens" which is essentially the
same thing as a mutex, kinda.
#include <windows.h>
volatile int did_something_happen =3D 0;
DWORD x(void* arg)
{
while (!did_something_happen)
Sleep(0);
printf("Happened\n");
return 0;
}
int main(int argc, char** argv)
{
CreateThread(NULL, 0, x, NULL, 0);
Sleep(5000);
did_something_happen =3D 1;
Sleep(1000);
return 1;
}
I'd say the best way to do it with Win32 would be if you can add a
non-visible static variable which contains the
LoadLibrary("kernel32.dll") and then a call to get the thread
condition function in that DLL, if it's non-null then use the Win32
stuff, if it is NULL, then make your own thread condition. If you want
threads to wake up from a call, the function setting the condition
stuff (called from the calling thread) can add stuff to some structure
of which condition to wake up on, then use the proper Win32
ResumeThread/SuspendThread. If the suspended thread happens to wakeup,
recheck the condition to see if it really happened and resume if it
did.
On Tue, Aug 31, 2010 at 1:28 AM, NightStrike <[email protected]> wrote:
> On Thu, Aug 26, 2010 at 7:18 AM, Kai Tietz <[email protected]> wrote:
>> 2010/8/26 Ruben Van Boxem <[email protected]>:
>>>
>>>>
>>>> but poking around, I do not find a "thread" file (the include file
>>>> for std::thread).
>>>
>>> it should be in:
>>> <gcc-src>/libstdc++-v3/include/std
>>>
>>>>
>>>> My mingw gcc installation does have a "thread" file. (I realize that
>>>> it may be out of date, but it's all I have.) I see, as Ruben pointed
>>>> out, that it references (either directly or indirectly)
>>>>
>>>> __gthread_cond_t
>>>> __gthread_time_t
>>>>
>>>> (and related), and that these are not defined in gthr-win32.h.
>>>
>>> As I said, *time_t is easy, but *cond_t seems like a big problem, because
>>> the whole concept of threading is different and there's far from a 1-on-1
>>> mapping of *cond_t to win32 API. Once we have that struct though, it should
>>> be quite straightforward to get the functions implemented. The gthr-win32.h
>>> header is located in
>>>
>>> gcc trunk/4.6 snapshot:
>>> gcc/gthr-win32.h
>>> gcc/config/i386/gthr-win32.c
>>>
>>> This last one will either need
>>>
>>>>
>>>> Do I take it correctly that the windows version of gthreads does
>>>> not implement all of the features in the linux/posix version, and
>>>> that some of these features are needed by the gcc implementation
>>>> of std::thread?
>>>>
>>>> And that our discussion here is basically about sticking with the
>>>> existing gcc implementation of std::thread and getting it to work
>>>> on windows by adding the missing features to the windows
>>>> version of gthreads?
>>>
>>> Correct.
>>
>> As I said before, if those functions are implemented in
>> gcc/gthr-win32.h and gcc/config/i386/gthr-win32-c, then we can define
>> in gthr-win32.h the define to support CXX0X.
>>
>
> Adding GD to the list
>
> ------------------------------------------------------------------------------
> This SF.net Dev2Dev email is sponsored by:
>
> Show off your parallel programming skills.
> Enter the Intel(R) Threading Challenge 2010.
> http://p.sf.net/sfu/intel-thread-sfd
> _______________________________________________
> Mingw-w64-public mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
--
Yeah...
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public