Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <process.h>
- #include <iostream>
- typedef struct {
- int data1;
- int data2;
- } t;
- void ThreadFunc(void* data) {
- // Do stuff. This will be the first function called on the new thread.
- // When this function returns, the thread goes away. See MSDN for more details.
- int j = 0;
- t *args = (t*) data;
- j = args->data2;
- int k = args->data1;
- if (k == -1) printf("+");
- while (j < 1000) {
- printf("(%d) ", j);
- j++;
- }
- }
- int main() {
- int i = 0;
- while (i < 5) {
- printf("C");
- i++;
- }
- int amount = 2;
- t arg;
- arg.data1 = -1;
- arg.data2 = 7;
- HANDLE thread = (HANDLE)_beginthread(&ThreadFunc, 0, (void*) &arg);
- if (thread) {
- // Optionally do stuff, such as wait on the thread.
- }
- i = 0;
- while (i < 100) {
- printf("%d ", i);
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement