threads programming

goodafternoon everybody.i am trying to create threads with Pthread library.i wrote my code and complided it.after compiling it i goet following syntax errors.
Warning 2 warning C4627: '#include <pthread.h>': skipped when looking for precompiled header use c:\users\222\documents\visual studio 2013\projects\lab2\lab2\lab2.cpp 3 1 lab2
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\222\documents\visual studio 2013\projects\lab2\lab2\lab2.cpp 24 1 lab2
Error 4 error C2143: syntax error : missing ',' before '*' c:\users\222\documents\visual studio 2013\projects\lab2\lab2\lab2.cpp 24 1 lab2
Error 5 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\222\documents\visual studio 2013\projects\lab2\lab2\lab2.cpp 25 1 lab2
Error 6 error C2143: syntax error : missing ',' before '*' c:\users\222\documents\visual studio 2013\projects\lab2\lab2\lab2.cpp 25 1 lab2
someone can help me?
here is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  #include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include  "stdafx.h"
typedef unsigned long int pthread_t;

void* function1(void *param)
{
	for (int i = 0; i < 1000000; i++)
		fprintf(stdout, "first thread processing %d\n", i);

}

void* function2(void *param)
{
	for (int i = 0; i < 1000000; i++)
		fprintf(stdout, "second thread processing %d\n", i);
}

int main()
{
	pthread_t mythread1 ;
	pthread_t mythread2 ;
	void pthread_create(pthread_t *mythread1, const pthread_attr_t *attr, void* function1, void *param);
	void pthread_create(pthread_t *mythread2, const pthread_attr_t *attr, void* function1, void *param);

	for (int i = 0; i < 1000000; i++)
		fprintf(stdout, "main thread processing %d\n", i);
	return 1;
}



Either turn off the precompiled stuff in Visual Studio project settings or move #include "stdafx.h" before any other include.
If you're using a default windows compiler pthreads aren't supported, that's a unix thing. If you want to use threading in windows, you'll want to use the winapi relevant functions.
Unless low-level, platform-specific functionality is required (for instance, we want to use kernel-supported thread pools on Windows), consider using the standard C++ library.

A series of tutorial articles:
https://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-1-starting-threads.html
Topic archived. No new replies allowed.