İşaretçi olmayan bir int için bir işaretçiyi yayınlamak sonra işaretçiye geri vermek mümkün mü? İşaretçiyi pthread_t değişkeninde bir yapıya kaydetmeye çalışıyorum, ancak çalışmayı başaramıyorum. İşte kodumun bazı parçacıkları (kullanıcı düzeyinde bir iş parçacığı yönetimi kitaplığı oluşturuyorum). İş parçacığı sırasını yazdırmaya çalıştığımda bana uzun bir çöp numarası veriyor.İşaretçinin adresini imzasız bir int içinde kaydetme C
Düzeltme: Boşver, işe aldım.
Ben içinthread = (pthread_t) currentThread;
değişti
*thread = (pthread_t) currentThread;
böyle aptalca bir şeydi düşündüm.
Testi programı:
pthread_t thread1;
pthread_t thread2;
pthread_create(&thread1, NULL, runner, NULL);
pthread_create(&thread2, NULL, runner, NULL);
pthread_join(&thread2, NULL);
Kütüphanem:
typedef struct queueItem
{
int tid;
ucontext_t context;
int caller;
struct queueItem *joiningOn;
struct queueItem *nextContext;
} queueItem;
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg)
{
thread = (pthread_t) currentThread;
}
...
int pthread_join(pthread_t thread, void **retval)
{
queueItem *t = (queueItem *) thread;
if(runningContext->joiningOn != NULL) // Current thread is already waiting on another
return EINVAL;
if(t == NULL) // If thread to join on is invalid
return 0;
fprintf(stdout, "JOINEE: %d\n", t->tid); // Prints weird number
runningContext->caller = JOIN;
runningContext->joiningOn = t;
swapcontext(&(runningContext->context), &scheduleContext);
}
anlamıyorum - kendi kütüphanesinde sen pthread_create tanımladığınız? Neden bir isim bu isimle normal işlevle çakışır? –
Okul için bir proje. –
Nevermind, işe koyuldu. Orijinal gönderimi düzenledim. –